const co = require('co');
var  mys = require('mysql');
const activityDao = require('../../model/act/activity');
const controllerBase = require('../../core/controllerBase');
const errEnum = require("../../common/enum");
const validator = require("validator");
const config = require('../../configuration.json');
var date = require("silly-datetime");
class Indexcontroller extends controllerBase {
    /*
     * 类构造函数
     * 设置类需要的数据实体操作实例
     */
    constructor(application) {
        ///将对应的数据库实体对象传递至基类
        super(application, new activityDao());
    }

    initializeRouter(instance) { 
        //#提交留言
        this.app.get('/api/saveLy', function (req, res) {
            co(instance.saveLy(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });


        //#获取SEO
        this.app.get('/api/seo', function (req, res) {
            co(instance.seo(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });



        //#获取首页数据
        this.app.get('/api/indexAll', function (req, res) {
            co(instance.indexAll(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });

        //#获取关于我们
        this.app.get('/api/aboutAll', function (req, res) {
            co(instance.aboutAll(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });


        //#获取产品中心
        this.app.get('/api/productAll', function (req, res) {
            co(instance.productAll(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });
        //#获取产品分页
        this.app.get('/api/productPage/:catelog_id', function (req, res) {
            co(instance.productPage(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });
        //#获取产品详情
        this.app.get('/api/productDetail/:article_id', function (req, res) {
            co(instance.productDetail(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        }); 


        //#获取新闻 
        this.app.get('/api/newsAll', function (req, res) {
            co(instance.newsAll(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });
        //#获取新闻分页
        this.app.get('/api/newsPage/:page', function (req, res) {
            co(instance.newsPage(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });
        //#获取新闻详情
        this.app.get('/api/newsDetail/:article_id', function (req, res) {
            co(instance.newsDetail(req, res))
                .then(result => instance.responseResult(req, res, result))
                .catch(result => instance.responseResult(res, res, result))
        });

    }

    * saveLy(req, res) {
        let r = {};
        let lyname = req.query.lyname;
        let lyemail = req.query.lyemail;
        let lyphone = req.query.lyphone;
        let lynote = req.query.lynote;  
        let sql = `INSERT INTO ly (lyname, lyemail, lyphone, lynote) VALUES ('${lyname}', '${lyemail}', '${lyphone}', '${lynote}' )`;
        let result = yield this._daoModel.query(sql);
        r = result.rows
        return {
            code: 1,
            successed: true,
            rows: r

        }
    }

    //seo
    * seo(req, res) {
        let r = {};   
        let seosql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_brief,hbn,article_cover FROM cnt_article where  catelog_id=18 limit 1`  ;
        let seo = yield this._daoModel.query(seosql);
        r.seo = seo.rows[0]

        return {
            code: 200,
            successed: true, 
            seo:seo
        }
    }


    //首页数据
    * indexAll(req, res) {
        let r = {};

        // 导航
        let sySql = `SELECT catelog_id,catelog_name as nameit,ext_field3,ext_field2,catelog_index FROM cnt_catelog where catelog_index=2 or catelog_index=6 and rec_isdeleted=0  order by catelog_id `  ;
        let resultsy = yield this._daoModel.query(sySql);
        r.dh=resultsy.rows
        
        // logo
        let logoSql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  catelog_id= 1`  ;
        let resultlogo = yield this._daoModel.query(logoSql);
        r.logo = resultlogo.rows[0]


        // banner
        let bannerSql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  catelog_id= 16 and pid=1 limit 5`  ;
        let resultbanner = yield this._daoModel.query(bannerSql);
        r.banner = resultbanner.rows
 
    
        // 先查出所有的电池分类
        let dc4Sql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover,article_label FROM cnt_article where  catelog_id in (6,7,8,9) and pid=0`  ;
        let resultdc4 = yield this._daoModel.query(dc4Sql);

        // 自行车分类的产品
        let dczxcSql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  pid= 66 limit 4 `   ;
        let resultdc4zxc = yield this._daoModel.query(dczxcSql);
        // 把自行车分类的产品加入到数据里
        resultdc4.rows[0].list= resultdc4zxc.rows

        // 电动滑板车分类的产品
        let dchbcSql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  pid= 77 limit 4 `   ;
        let resultdc4hbc = yield this._daoModel.query(dchbcSql);
        // 把电动滑板车分类的产品加入到数据里
        resultdc4.rows[1].list= resultdc4hbc.rows

        // 电摩分类的产品
        let dcdmSql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  pid= 88 limit 4 `   ;
        let resultdc4dm = yield this._daoModel.query(dcdmSql);
        // 把电摩分类的产品加入到数据里
        resultdc4.rows[2].list= resultdc4dm.rows

        // 自家电动车分类的产品
        let dczjddcSql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  pid= 99 limit 4 `   ;
        let resultdc4zjddc = yield this._daoModel.query(dczjddcSql);
        // 把电摩分类的产品加入到数据里
        resultdc4.rows[3].list= resultdc4zjddc.rows

        // 最后把四组分类输出到前端
        r.dc4 = resultdc4.rows

        //  关于我们  article_brief
        let aboutSql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_brief,hbn,article_cover FROM cnt_article where  catelog_id=2`  ;
        let resultAbout = yield this._daoModel.query(aboutSql);
        r.About = resultAbout.rows[0]


        //  荣誉
        let rySql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_share FROM cnt_article where  catelog_id=11`  ;
        let resultRy = yield this._daoModel.query(rySql);
        r.ry = resultRy.rows[0]


        //  公司新闻
        let gsxwSql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_brief,hbn,article_cover FROM cnt_article where  catelog_id=13 limit 1`  ;
        let resultGsxw = yield this._daoModel.query(gsxwSql);
        r.gsxw = resultGsxw.rows 

        //  行业新闻
        let hyxwSql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_brief,hbn,article_cover FROM cnt_article where  catelog_id=14 limit 2`  ;
        let resultHyxw = yield this._daoModel.query(hyxwSql);
        r.hyxw = resultHyxw.rows 

        //  疑难问答
        let ynwdSql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_brief,hbn,article_cover FROM cnt_article where  catelog_id=15 limit 2`  ;
        let resultYnwd = yield this._daoModel.query(ynwdSql);
        r.ynwd = resultYnwd.rows 

        return {
            code: 200,
            successed: true,
            dh:r.dh,
            logo: r.logo,
            banner: r.banner,
            dc4:r.dc4,
            about:r.About,
            ry:r.ry,
            gsxw:r.gsxw,
            hyxw:r.hyxw,
            ynwd:r.ynwd
        }
    }

    //关于我们数据
    * aboutAll(req, res) {

        let r = {};

        // banner
        let bannerSql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  catelog_id= 16 and pid=2 limit 1`  ;
        let resultbanner = yield this._daoModel.query(bannerSql);
        r.banner = resultbanner.rows

        //  关于我们  article_brief
        let aboutSql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_brief,hbn,article_cover FROM cnt_article where  catelog_id=2`  ;
        let resultAbout = yield this._daoModel.query(aboutSql);
        r.About = resultAbout.rows[0]

        //  企业文化
        let qywhSql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_brief,hbn,article_cover FROM cnt_article where  catelog_id=10`  ;
        let resultQywh = yield this._daoModel.query(qywhSql);
        r.qywhS = resultQywh.rows[0]
        

        //  荣誉
        let rySql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_share FROM cnt_article where  catelog_id=11`  ;
        let resultRy = yield this._daoModel.query(rySql);
        r.ry = resultRy.rows[0]


        return {
            code: 200,
            successed: true, 
            banner: r.banner, 
            about:r.About,
            qywhS:r.qywhS,
            ry:r.ry,
            gsxw:r.gsxw,
            hyxw:r.hyxw,
            ynwd:r.ynwd
        }

    }

    //新闻
    * newsAll(req, res) {
        let r = {};
        // banner
        let bannerSql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover,article_brief,hbn  FROM cnt_article where  catelog_id= 16 and pid=4 limit 1 `  ;
        let resultbanner = yield this._daoModel.query(bannerSql);
        r.banner = resultbanner.rows            
        
        // 先查出所有的news
        let allSql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover,article_brief,hbn FROM cnt_article where  catelog_id in (13,14,15)  `  ;  
        let resultAllnews = yield this._daoModel.query(allSql);
        r.total = resultAllnews.rows.length; 

        // 再查出10条新闻
        let newsSql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover,article_brief,hbn FROM cnt_article where  catelog_id in (13,14,15) limit 10 `  ;  ;
        let resultnews = yield this._daoModel.query(newsSql);
            
        // 最后把四组分类输出到前端
        r.news = resultnews.rows

        return {
            code: 200,
            successed: true, 
            banner: r.banner, 
            total:r.total,
            news:r.news

        }
    }


    //news分页
    * newsPage(req, res) {
        let r = {}; 
        // let catelog_id = req.params.catelog_id; 
        let page = req.params.page; 
        let num=10;
        let sql_home_base ="";
                    //分页
                    if (page) {
                        let pageNo = 0
                        if (num) {
                            pageNo = (page - 1) * num
                        } else {
                            num = 10
                            pageNo = (page - 1) * num
                        }
                        sql_home_base += ` LIMIT ${pageNo},${num}  `
                    } else {
                        sql_home_base += ` LIMIT 0, 10`
                    }


            // 先查出所有的news
            let newsSql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover,article_brief,hbn FROM cnt_article where  catelog_id in (13,14,15)  `  ;  
            let resultnews = yield this._daoModel.query(newsSql);
            r.total = resultnews.rows.length; 

            //本页10条 
            let news10 = 'SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where catelog_id in (13,14,15)   '+ sql_home_base   ; 
            let resultNews10 = yield this._daoModel.query(news10);

            // 最后把四组分类输出到前端
            r.news = resultNews10.rows

            
        return {
            code: 200,
            successed: true, 
            total:r.total,
            news:r.news
        }
    }



    //新闻
    * newsDetail(req, res) {
        let r = {}; 
        let article_id = req.params.article_id; 

        // 先查出此ID的新闻
        // let dc1Sql = `SELECT * FROM bas_richtext where  data_id = "${article_id}" and rec_isdeleted=0 `  ;
        let dc1Sql = `SELECT * FROM bas_richtext where  data_id = "00577a6d-67c5-4e0b-807c-ff317617c178"   `  ;
        r.news = yield this._daoModel.query(dc1Sql);
    
        return {
            code: 200,
            successed: true, 
            news:r.news.rows[0]
        }
    }

    //产品数据
    * productAll(req, res) {
        let r = {};
        // banner
        let bannerSql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  catelog_id= 16 and pid=3 limit 1`  ;
        let resultbanner = yield this._daoModel.query(bannerSql);
        r.banner = resultbanner.rows

    
        // 先查出所有的电池分类
        let dc4Sql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  catelog_id in (6,7,8,9) and pid=0`  ;
        let resultdc4 = yield this._daoModel.query(dc4Sql);

        // 自行车分类的产品
        let dczxcSql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  pid= 66 limit 12 `   ;
        let resultdc4zxc = yield this._daoModel.query(dczxcSql);
        // 把自行车分类的产品加入到数据里
        resultdc4.rows[0].list= resultdc4zxc.rows

         //算出此条件下的总条数
        let allCountSql1 = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  pid= 66  `   ;
        let resultAllCount1 = yield this._daoModel.query(allCountSql1);
        resultdc4.rows[0].total = resultAllCount1.rows.length; 

        // 电动滑板车分类的产品
        let dchbcSql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  pid= 77 limit 12 `   ;
        let resultdc4hbc = yield this._daoModel.query(dchbcSql);
        // 把电动滑板车分类的产品加入到数据里
        resultdc4.rows[1].list= resultdc4hbc.rows

         //算出此条件下的总条数
         let allCountSql2 = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  pid= 77  `   ;
         let resultAllCount2 = yield this._daoModel.query(allCountSql2);
         resultdc4.rows[1].total = resultAllCount2.rows.length; 



        // 电摩分类的产品
        let dcdmSql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  pid= 88 limit 12 `   ;
        let resultdc4dm = yield this._daoModel.query(dcdmSql);
        // 把电摩分类的产品加入到数据里
        resultdc4.rows[2].list= resultdc4dm.rows

         //算出此条件下的总条数
         let allCountSql3 = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  pid= 88  `   ;
         let resultAllCount3 = yield this._daoModel.query(allCountSql3);
         resultdc4.rows[2].total = resultAllCount3.rows.length; 



        // 自家电动车分类的产品
        let dczjddcSql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  pid= 99 limit 12 `   ;
        let resultdc4zjddc = yield this._daoModel.query(dczjddcSql);
        // 把电摩分类的产品加入到数据里
        resultdc4.rows[3].list= resultdc4zjddc.rows

        //算出此条件下的总条数
        let allCountSql4 = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  pid= 88  `   ;
        let resultAllCount4 = yield this._daoModel.query(allCountSql4);
        resultdc4.rows[3].total = resultAllCount4.rows.length; 

        // 最后把四组分类输出到前端
        r.dc4 = resultdc4.rows
        return {
            code: 200,
            successed: true, 
            banner: r.banner, 
            dc4:r.dc4
        }
    }

 
    //产品数据
    * productPage(req, res) {

        let r = {}; 
        let catelog_id = req.params.catelog_id; 
        let page = req.query.page; 
        let num=12;
        let sql_home_base ="";
                    //分页
                    if (page) {
                        let pageNo = 0
                        if (num) {
                            pageNo = (page - 1) * num
                        } else {
                            num = 10
                            pageNo = (page - 1) * num
                        }
                        sql_home_base += ` LIMIT ${pageNo},${num}  `
                    } else {
                        sql_home_base += ` LIMIT 0, 12`
                    }



        if(catelog_id==66){
            
            // 先查出所有的电池分类
            let dc4Sql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  catelog_id in (6) and pid=0`  ;
            let resultdc4 = yield this._daoModel.query(dc4Sql);
            // 自行车分类的产品
            let dczxcSql = 'SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  pid= 66 '+ sql_home_base   ;
            let resultdc4zxc = yield this._daoModel.query(dczxcSql);
            // 把自行车分类的产品加入到数据里
            resultdc4.rows[0].list= resultdc4zxc.rows    

            //算出此条件下的总条数
            let allCountSql1 = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  pid= 66  `   ;
            let resultAllCount1 = yield this._daoModel.query(allCountSql1);
            resultdc4.rows[0].total = resultAllCount1.rows.length; 

            // 最后把四组分类输出到前端
            r.dc4 = resultdc4.rows

        }else if(catelog_id==77){

        // 先查出所有的电池分类
        let dc4Sql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  catelog_id in (7) and pid=0`  ;
        let resultdc4 = yield this._daoModel.query(dc4Sql);
            // 电动滑板车分类的产品
            let dchbcSql = 'SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  pid= 77'+ sql_home_base   ;
            let resultdc4hbc = yield this._daoModel.query(dchbcSql);
            // 把电动滑板车分类的产品加入到数据里
            resultdc4.rows[0].list= resultdc4hbc.rows 

            //算出此条件下的总条数
            let allCountSql2 = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  pid= 77  `   ;
            let resultAllCount2 = yield this._daoModel.query(allCountSql2);
            resultdc4.rows[0].total = resultAllCount2.rows.length; 

            // 最后把四组分类输出到前端
            r.dc4 = resultdc4.rows

        }else if(catelog_id==88){

                    // 先查出所有的电池分类
            let dc4Sql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  catelog_id in (8) and pid=0`  ;
            let resultdc4 = yield this._daoModel.query(dc4Sql);

            // 电摩分类的产品
            let dcdmSql = 'SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  pid= 88'+ sql_home_base   ;
            let resultdc4dm = yield this._daoModel.query(dcdmSql);
            // 把电摩分类的产品加入到数据里
            resultdc4.rows[0].list= resultdc4dm.rows

            //算出此条件下的总条数
            let allCountSql3 = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  pid= 88  `   ;
            let resultAllCount3 = yield this._daoModel.query(allCountSql3);
            resultdc4.rows[0].total = resultAllCount3.rows.length; 
            
            // 最后把四组分类输出到前端
            r.dc4 = resultdc4.rows

        } else{
                    // 先查出所有的电池分类
        let dc4Sql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  catelog_id in (9) and pid=0`  ;
        let resultdc4 = yield this._daoModel.query(dc4Sql);

            // 自家电动车分类的产品
            let dczjddcSql = 'SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  pid= 99'+ sql_home_base   ;
            let resultdc4zjddc = yield this._daoModel.query(dczjddcSql);
            // 把电摩分类的产品加入到数据里
            resultdc4.rows[0].list= resultdc4zjddc.rows

            //算出此条件下的总条数
            let allCountSql4 = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  pid= 99  `   ;
            let resultAllCount4 = yield this._daoModel.query(allCountSql4);
            resultdc4.rows[0].total = resultAllCount4.rows.length; 

            // 最后把四组分类输出到前端
            r.dc4 = resultdc4.rows

        }

        return {
            code: 200,
            successed: true, 
            dc4:r.dc4
        }
    }



    
    //产品数据  productDetail:/article_id
    * productDetail(req, res) {

        let r = {}; 
        let article_id = req.params.article_id; 

        // 先查出此ID的电池
        let dc1Sql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover,article_brief,hbn,article_share FROM cnt_article where  article_id = "${article_id}" and rec_isdeleted=0 `  ;
        let resultdc1 = yield this._daoModel.query(dc1Sql);
    
        // 最后 输出到前端sss
        r.dc1 = resultdc1.rows
        return {
            code: 200,
            successed: true, 
            dc1:r.dc1
        }
    }



    //获取所有的检查
    * listHB(req, res) {

        let r = {};

        // banner
        let bannerSql = `SELECT article_id,catelog_id,article_title as nameit,ext_field3,article_cover FROM cnt_article where  catelog_id= 16 and pid=4 limit 1`  ;
        let resultbanner = yield this._daoModel.query(bannerSql);
        r.banner = resultbanner.rows


    }


    //获取所有的检查
    * listHB(req, res) {
        let uid = req.body.uid;
        let page = req.body.page;
        let num = req.body.num;
        let name = req.body.name;
        let ys = req.body.ys;
        let sq = req.body.sq;
        let qy = req.body.qy;
        let jd = req.body.jd;
        let startTime = req.body.startTime;
        let endTime = req.body.endTime;
        let cslx = req.body.cslx;

        let a = req.body.a;
        let here = yield this.checkuser(uid, a);
        if (here == 0) {
            return {
                code: -1,
                here: 0,
                successed: true,
                msg: "请重新登陆"
            }
        }

        let r = {}
        let sql_sort = `select * from home_kfs where id = '${uid}'`;
        let user = yield this._daoModel.query(sql_sort);
        let user_sort = user.rows[0].sort;
        let user_sf = user.rows[0].sf;
        let user_sq = user.rows[0].sq;
        let user_qy = user.rows[0].qy;
        let user_jd = user.rows[0].jd;

        let sql_home_base = `SELECT hb.name, hb.hxid, hb.id as hbid, hb.pic, hb.pics, hb.id_card, hb.sq, hb.qy, hb.jd, hb.address, kfs.name as kfsname,  hb.ys, hb.sh_time, hb.zg_time,  hb.note, hb.create_time,hb.uid as hbuid FROM home_base hb   inner join home_kfs kfs on hb.kfs_id=kfs.id where hb.del=0  `;
        if (name) sql_home_base += `and hb.name like '%` + name + `%'`;
        if (cslx) sql_home_base += `and hb.cslx like '%` + cslx + `%'`;
        if (startTime) sql_home_base += ` and hb.sh_time >= '${startTime} 00:00:00' `;
        if (endTime) sql_home_base += ` and hb.sh_time <= '${endTime} 23:59:59' `;

        if (user_sort == 0) {
            sql_home_base += ` and hb.sf = '${user_sf}'`;
            if (sq) sql_home_base += ` and hb.sq = '${sq}'`;
            if (sq && qy) sql_home_base += ` and hb.qy = '${qy}'`;
            if (sq && qy && jd) sql_home_base += ` and hb.jd = '${jd}'`;
        }

        if (user_sort == 1) {
            sql_home_base += ` and hb.sf = '${user_sf}' and hb.sq = '${user_sq}'`;
            if (qy) sql_home_base += ` and hb.qy = '${qy}'`;
            if (qy && jd) sql_home_base += ` and hb.jd = '${jd}'`;
        }

        if (user_sort == 2) {
            sql_home_base += ` and hb.sf = '${user_sf}' and hb.sq = '${user_sq}' and hb.qy = '${user_qy}'`;
            if (jd) sql_home_base += ` and hb.jd = '${jd}'`;
        }

        //如果当今级别是街道的 就只能看到自己录入的单位
        if (user_sort == 3)
            sql_home_base += ` and hb.jd = '${user_jd}' and hb.uid = '${uid}' `;

        //由于默认为绿色 为了避免前端搜索的时候把没检查完的都搜索出来 所以要加上第几步这个条件
        if (ys == 0)
            sql_home_base += ` and  ys=0  order by hb.id desc  `
        else if (ys == 1)
            //` and hb.id in ( select DISTINCT pid  from home_base_hx where ys=1  and del=0 and djb=10 )`
            sql_home_base += ` and ys=1  order by hb.id desc `
        else if (ys == 2)
            //` and hb.id in ( select DISTINCT pid  from home_base_hx where ys=2  and del=0 and djb=10 )`
            sql_home_base += ` and ys=2  order by hb.id desc `
        else if (ys == 3)
            //由于默认为绿色 ` and hb.id in ( select DISTINCT pid  from home_base_hx where ys=3  and del=0  )`
            sql_home_base += ' and ys=3 order by hb.id desc '
        else if (ys == 12)
            //同时红色和黄色 ` and hb.id in ( select DISTINCT pid  from home_base_hx where (ys=1 or ys=2) and del=0  )`
            sql_home_base += ' and (ys=1 or ys=2) order by hb.ys , hb.id desc '
        else
            sql_home_base += `  order by hb.ys , hb.id desc `;

        //算出此条件下的总条数
        let resultAllCount = yield this._daoModel.query(sql_home_base);
        let allCount = resultAllCount.rows.length;

        //分页
        if (page) {
            let pageNo = 0
            if (num) {
                pageNo = (page - 1) * num
            } else {
                num = 10
                pageNo = (page - 1) * num
            }
            sql_home_base += ` LIMIT ${pageNo},${num}  `
        } else {
            sql_home_base += ` LIMIT 0,100`
        }
        let result = yield this._daoModel.query(sql_home_base);

        result.rows.map((item, index) => {
            if (item.pics.indexOf('http') == -1) {
                item.pics = config.appsetting.picHead + item.pics;
            }
            if (!item.sh_time) {
                item.sh_time = "暂没排查"
            }

            // 标识此记录是否自己创建
            if (item.hbuid==uid) {
                item.Icreate = 1
            }else{
                item.Icreate = 0
            }

            if ((item.ys == 1 || item.ys == 2) && item.zg_time) {
                let sy_time = item.zg_time;
                var a1 = Date.parse(new Date(sy_time));  //整改时间
                var a2 = Date.parse(new Date());  //当前时间
                item.zg_time = parseInt((a1 - a2) / (1000 * 60 * 60 * 24));
                if (sy_time == 0) item.zg_time = 1;
            }
            if (item.ys == 3 || item.ys == 0) {
                delete item.zg_time;
            }

            if (ys == 0) item.ys = 0;

        })

        let arrHomeBase = result.rows
        r.arrHomeBase = arrHomeBase

        return {
            code: 1,
            usort: user_sort,
            usf: user_sf,
            usq: user_sq,
            uqy: user_qy,
            ujd: user_jd,
            successed: true,
            rows: r,
            name: name,
            ys: ys,
            allCount: allCount
        }
    }

    * getInsertHb(req, res) {
        let r = {};
        let name = req.body.name;
        let fr = req.body.fr;
        let idCard = req.body.id_card;
        let uid = req.body.uid;
        let a = req.body.a;
        let here = yield this.checkuser(uid, a);
        if (here == 0) {
            return {
                code: -1,
                here: 0,
                successed: true,
                msg: "请重新登陆"
            }
        }

        let pics = req.body.pics;
        let phone = req.body.phone;
        let sf = req.body.sf;
        let sq = req.body.sq;
        let qy = req.body.qy;
        let jd = req.body.jd;
        let address = req.body.address;
        let today = date.format(new Date(), 'YYYY-MM-DD HH:mm:ss'); //当前时间
        let sql = `INSERT INTO home_base(name, fr, id_card, uid, kfs_id, check_time, pics, phone, sf, sq, qy, jd, address, xszt) VALUES ('${name}', '${fr}', '${idCard}', '${uid}', '${uid}', '${today}', '${pics}', '${phone}', '${sf}', '${sq}', '${qy}', '${jd}', '${address}', '0')`;
        let result = yield this._daoModel.query(sql);
        r = result.rows
        return {
            code: 1,
            successed: true,
            rows: r

        }
    }

    //detailHb
    * detailHb(req, res) {
        let r = {};
        let hxid = req.params.hxid;
        let sql = `SELECT hb.id as hbid, hx.id as hxid, hb.name, hb.fr, hx.ys as hxys, hx.sh_note , hx.zg_time, hx.create_time, hb.address, hx.note FROM home_base hb inner join home_base_hx hx on hb.id=hx.pid where hx.id= ` + hxid;
        let result = yield this._daoModel.query(sql);
        result.rows[0].create_time = date.format(result.rows[0].create_time, 'YYYY-MM-DD');
        r = result.rows[0]
        return {
            code: 1,
            successed: true,
            rows: r
        }
    }


    //detailHb
    * detailHbById(req, res) {
        let r = {};
        let id = req.params.id;
        let sql = `SELECT * FROM home_base  where  id= ` + id;
        let result = yield this._daoModel.query(sql);
        r = result.rows[0]
        return {
            code: 1,
            successed: true,
            rows: r
        }
    }

    * login(req, res) {

        //当前时间戳
        let timespan = Math.round(new Date().getTime() / 1000);

        let un =  req.body.un ;
        let psw =  req.body.psw ;

        let r = {};
        let sql = `SELECT * FROM home_kfs where del=0 and name="` + un + '" and psw="' + psw + '"' + ' order by id desc ';
        let us = yield this._daoModel.query(sql);
        if (us.rows.length > 0) {
            //修改数据库当前登录的时间戳
            yield this._daoModel.query('update home_kfs set a="' + timespan + '"' + ' where id=' + us.rows[0].id);

            //修改当前a的值 用来返回前端
            us.rows[0].a = timespan;
            return {
                code: 1,
                successed: true,
                us: us.rows[0],
                un: un
            }
        } else {
            return {
                code: 0,
                successed: false,
                msg: "账号或密码或身份状态等错误",
                un: un
            }
        }

    }

    * getHxPj(req, res) {

        let uid = req.body.uid;
        let a = req.body.a;
        let here = yield this.checkuser(uid, a);
        if (here == 0) {
            return {
                code: -1,
                here: 0,
                successed: true,
                msg: "请重新登陆"
            }
        }

        let r = {};
        let hxId = req.body.hxId;

        //查询该条检查是否由该登陆着创建的
        let result = yield this._daoModel.query(`select * from home_base where uid='${uid}' and id= (select pid FROM  home_base_hx where id = '${hxId}')  `);
        if (result.rows.length == 0) {
            return {
                code: 0,
                successed: false,
                msg: "该公司不是您创建，不能参与排查"
            }
        }


        let pj = req.body.pj;
        let sql = `SELECT `
        if (pj == 1) sql += ` get_live, get_live_info, get_live_pic1, get_live_pic2 ,get_live_pic3, get_live_pic4, get_live_pic5, get_live_pic6 `;
        if (pj == 2) sql += ` get_away, get_away_info, get_away_pic1, get_away_pic2, get_away_pic3, get_away_pic4, get_away_pic5, get_away_pic6 `;
        if (pj == 3) sql += ` get_line, get_line_info, get_line_pic1, get_line_pic2, get_line_pic3, get_line_pic4, get_line_pic5, get_line_pic6 `;
        if (pj == 4) sql += ` get_electric, get_electric_info, get_electric_pic1, get_electric_pic2, get_electric_pic3, get_electric_pic4, get_electric_pic5, get_electric_pic6`;
        if (pj == 5) sql += ` get_firetool, get_firetool_info, get_firetool_pic1, get_firetool_pic2, get_firetool_pic3, get_firetool_pic4, get_firetool_pic5, get_firetool_pic6`;
        if (pj == 6) sql += ` get_saveaway, get_saveaway_info, get_saveaway_pic1, get_saveaway_pic2, get_saveaway_pic3,get_saveaway_pic4, get_saveaway_pic5, get_saveaway_pic6`;
        if (pj == 7) sql += ` get_carstop, get_carstop_info, get_carstop_pic1, get_carstop_pic2, get_carstop_pic3, get_carstop_pic4, get_carstop_pic5, get_carstop_pic6`;
        if (pj == 8) sql += ` get_easyfire, get_easyfire_info, get_easyfire_pic1, get_easyfire_pic2, get_easyfire_pic3, get_easyfire_pic4, get_easyfire_pic5, get_easyfire_pic6`;
        if (pj == 9) sql += ` get_save, get_save_info, get_save_pic1, get_save_pic2, get_save_pic3, get_save_pic4, get_save_pic5, get_save_pic6`;
        if (pj == 10) sql += ` other, other_info, other_pic1, other_pic2, other_pic3, other_pic4, other_pic5, other_pic6`;

        sql += ` FROM home_base_hx where id = '${hxId}' `;
        let resultget = yield this._daoModel.query(sql);
        r = resultget.rows

        return {
            code: 1,
            successed: true,
            rows: r
        }
    }

    * updateHx(req, res) {
        let r = {};
        let id = req.body.id;
        let pj = req.body.pj;
        let val = req.body.val;
        let info = req.body.info;
        let pic1 = req.body.pic1;
        let pic2 = req.body.pic2;
        let pic3 = req.body.pic3;
        let pic4 = req.body.pic4;
        let pic5 = req.body.pic5;
        let pic6 = req.body.pic6;
        let pid = req.body.pid;
        let uid = req.body.uid;
        let a = req.body.a;
        let here = yield this.checkuser(uid, a);
        if (here == 0) {
            return {
                code: -1,
                here: 0,
                successed: true,
                msg: "请重新登陆"
            }
        }


        //查询该条检查是否由该登陆着创建的
        let result = yield this._daoModel.query(`select * from home_base where uid='${uid}' and id=   '${pid}'   `);
        if (result.rows.length == 0) {
            return {
                code: 0,
                successed: false,
                msg: "该公司不是您创建，不能参与排查"
            }
        }


        let islast = 0;//最后一步修改
        let isReset = req.body.isReset || 0; //判断是否新增还是重新设置
        //默认绿色
        let ys = 3;
        if (!id) {
            return {
                code: 0,
                successed: false,
                msg: "请传hxid"
            }
        }

        // 只要有一项不符合要求就是红色 ys=1
        if (val == 1) {
            let sql2 = `UPDATE home_base_hx SET violations_num = violations_num+1 WHERE id = '${id}' `;
            yield this._daoModel.query(sql2);
        }

        // 设置更新时间
        let today = date.format(new Date(), 'YYYY-MM-DD HH:mm:ss'); //当前时间
        let sql = "";

        //如果已经走完十步 重新修改不需要修改第几步   
        let hxsql = `select * from home_base_hx where  id = '${id}' `;
        let hxResult = yield this._daoModel.query(hxsql);
        if (hxResult.rows[0].djb == 10)
            sql = `UPDATE home_base_hx SET uid='${uid}', update_time = '${today}' `;
        else
            sql = `UPDATE home_base_hx SET uid='${uid}', update_time = '${today}', djb = ${pj} `;

        //修改对应项    
        if (pj == 1) {
            sql += `,get_live = '${val}' `;
            if (!info) sql += `,get_live_info = NULL `; else sql += `,get_live_info = '${info}' `;
            if (!pic1 || "") sql += `,get_live_pic1 = NULL `; else sql += `,get_live_pic1 = '${pic1}' `;
            if (!pic2 || "") sql += `,get_live_pic2 = NULL `; else sql += `,get_live_pic2 = '${pic2}' `;
            if (!pic3 || "") sql += `,get_live_pic3 = NULL `; else sql += `,get_live_pic3 = '${pic3}' `;
            if (!pic4 || "") sql += `,get_live_pic4 = NULL `; else sql += `,get_live_pic4 = '${pic4}' `;
            if (!pic5 || "") sql += `,get_live_pic5 = NULL `; else sql += `,get_live_pic5 = '${pic5}' `;
            if (!pic6 || "") sql += `,get_live_pic6 = NULL `; else sql += `,get_live_pic6 = '${pic6}' `;
            sql += ` WHERE id = '${id}'`;
            yield this._daoModel.query(sql);

            //在此处开始根据违规  判断颜色
            let sqlwgx = `SELECT * FROM home_base_hx WHERE id = '${id}' `;
            let wgxall = yield this._daoModel.query(sqlwgx);
            //标记第几项违规
            let wgx = "不符合规范:第"
            // 如果不涉及(2)就不能统计 只统计0 1的
            let i = 0
            if (wgxall.rows[0].get_live != 2) {
                i += wgxall.rows[0].get_live          //1
                if (wgxall.rows[0].get_live == 1) wgx += "1项"
            }
            if (wgxall.rows[0].get_away != 2) {
                i += wgxall.rows[0].get_away          //2 
                if (wgxall.rows[0].get_away == 1) wgx += " 2项"
            }
            if (wgxall.rows[0].get_line != 2) {
                i += wgxall.rows[0].get_line          //3
                if (wgxall.rows[0].get_line == 1) wgx += " 3项"
            }
            if (wgxall.rows[0].get_electric != 2) {
                i += wgxall.rows[0].get_electric      //4
                if (wgxall.rows[0].get_electric == 1) wgx += " 4项"
            }
            if (wgxall.rows[0].get_firetool != 2) {
                i += wgxall.rows[0].get_firetool      //5
                if (wgxall.rows[0].get_firetool == 1) wgx += " 5项"
            }
            if (wgxall.rows[0].get_saveaway != 2) {
                i += wgxall.rows[0].get_saveaway      //6    
                if (wgxall.rows[0].get_saveaway == 1) wgx += " 6项"
            }
            if (wgxall.rows[0].get_carstop != 2) {
                i += wgxall.rows[0].get_carstop       //7
                if (wgxall.rows[0].get_carstop == 1) wgx += " 7项"
            }
            if (wgxall.rows[0].get_easyfire != 2) {
                i += wgxall.rows[0].get_easyfire      //8
                if (wgxall.rows[0].get_easyfire == 1) wgx += " 8项"
            }
            if (wgxall.rows[0].get_save != 2) {
                i += wgxall.rows[0].get_save          //9
                if (wgxall.rows[0].get_save == 1) wgx += " 9项"
            }
            if (wgxall.rows[0].other != 2) {
                i += wgxall.rows[0].other             //10
                if (wgxall.rows[0].other == 1) wgx += " 10项"
            }
            //根据违规项目判断颜色
            if (i == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 3, note = '符合规范'  WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            } else if (i >= 3 || wgxall.rows[0].get_live == 1) {
                let sql2 = `UPDATE home_base_hx SET ys = 1, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            } else if (i > 0 && i < 3 && wgxall.rows[0].get_live == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 2, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }


        } else if (pj == 2) {
            sql += ` ,get_away = '${val}'`
            if (!info) sql += `,get_away_info = NULL `; else sql += `, get_away_info = '${info}' `;
            if (!pic1 || "") sql += `,get_away_pic1 = NULL `; sql += `,get_away_pic1 = '${pic1}' `;
            if (!pic2 || "") sql += `,get_away_pic2 = NULL `; sql += `,get_away_pic2 = '${pic2}' `;
            if (!pic3 || "") sql += `,get_away_pic3 = NULL `; sql += `,get_away_pic3 = '${pic3}' `;
            if (!pic4 || "") sql += `,get_away_pic4 = NULL `; sql += `,get_away_pic4 = '${pic4}' `;
            if (!pic5 || "") sql += `,get_away_pic5 = NULL `; sql += `,get_away_pic5 = '${pic5}' `;
            if (!pic6 || "") sql += `,get_away_pic6 = NULL `; sql += `,get_away_pic6 = '${pic6}' `;
            sql += ` WHERE id = '${id}'`;
            yield this._daoModel.query(sql);

            //在此处开始根据违规  判断颜色
            let sqlwgx = `SELECT * FROM home_base_hx WHERE id = '${id}' `;
            let wgxall = yield this._daoModel.query(sqlwgx);
            //标记第几项违规
            let wgx = "不符合规范:第"
            // 如果不涉及(2)就不能统计 只统计0 1的
            let i = 0
            if (wgxall.rows[0].get_live != 2) {
                i += wgxall.rows[0].get_live          //1
                if (wgxall.rows[0].get_live == 1) wgx += "1项"
            }
            if (wgxall.rows[0].get_away != 2) {
                i += wgxall.rows[0].get_away          //2 
                if (wgxall.rows[0].get_away == 1) wgx += " 2项"
            }
            if (wgxall.rows[0].get_line != 2) {
                i += wgxall.rows[0].get_line          //3
                if (wgxall.rows[0].get_line == 1) wgx += " 3项"
            }
            if (wgxall.rows[0].get_electric != 2) {
                i += wgxall.rows[0].get_electric      //4
                if (wgxall.rows[0].get_electric == 1) wgx += " 4项"
            }
            if (wgxall.rows[0].get_firetool != 2) {
                i += wgxall.rows[0].get_firetool      //5
                if (wgxall.rows[0].get_firetool == 1) wgx += " 5项"
            }
            if (wgxall.rows[0].get_saveaway != 2) {
                i += wgxall.rows[0].get_saveaway      //6    
                if (wgxall.rows[0].get_saveaway == 1) wgx += " 6项"
            }
            if (wgxall.rows[0].get_carstop != 2) {
                i += wgxall.rows[0].get_carstop       //7
                if (wgxall.rows[0].get_carstop == 1) wgx += " 7项"
            }
            if (wgxall.rows[0].get_easyfire != 2) {
                i += wgxall.rows[0].get_easyfire      //8
                if (wgxall.rows[0].get_easyfire == 1) wgx += " 8项"
            }
            if (wgxall.rows[0].get_save != 2) {
                i += wgxall.rows[0].get_save          //9
                if (wgxall.rows[0].get_save == 1) wgx += " 9项"
            }
            if (wgxall.rows[0].other != 2) {
                i += wgxall.rows[0].other             //10
                if (wgxall.rows[0].other == 1) wgx += " 10项"
            }
            //根据违规项目判断颜色
            if (i == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 3, note = '符合规范'  WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            } else if (i >= 3 || wgxall.rows[0].get_live == 1) {
                let sql2 = `UPDATE home_base_hx SET ys = 1, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            } else if (i > 0 && i < 3 && wgxall.rows[0].get_live == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 2, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }

        } else if (pj == 3) {
            sql += ` ,get_line = '${val}'`
            if (!info) sql += `,get_line_info = NULL `; else sql += `, get_line_info = '${info}' `;
            if (!pic1 || "") sql += `,get_line_pic1 = NULL `; sql += `,get_line_pic1 = '${pic1}' `;
            if (!pic2 || "") sql += `,get_line_pic2 = NULL `; sql += `,get_line_pic2 = '${pic2}' `;
            if (!pic3 || "") sql += `,get_line_pic3 = NULL `; sql += `,get_line_pic3 = '${pic3}' `;
            if (!pic4 || "") sql += `,get_line_pic4 = NULL `; sql += `,get_line_pic4 = '${pic4}' `;
            if (!pic5 || "") sql += `,get_line_pic5 = NULL `; sql += `,get_line_pic5 = '${pic5}' `;
            if (!pic6 || "") sql += `,get_line_pic6 = NULL `; sql += `,get_line_pic6 = '${pic6}' `;
            sql += ` WHERE id = '${id}'`;
            yield this._daoModel.query(sql);

            //在此处开始根据违规  判断颜色
            let sqlwgx = `SELECT * FROM home_base_hx WHERE id = '${id}' `;
            let wgxall = yield this._daoModel.query(sqlwgx);
            //标记第几项违规
            let wgx = "不符合规范:第"
            // 如果不涉及(2)就不能统计 只统计0 1的
            let i = 0
            if (wgxall.rows[0].get_live != 2) {
                i += wgxall.rows[0].get_live          //1
                if (wgxall.rows[0].get_live == 1) wgx += "1项"
            }
            if (wgxall.rows[0].get_away != 2) {
                i += wgxall.rows[0].get_away          //2 
                if (wgxall.rows[0].get_away == 1) wgx += " 2项"
            }
            if (wgxall.rows[0].get_line != 2) {
                i += wgxall.rows[0].get_line          //3
                if (wgxall.rows[0].get_line == 1) wgx += " 3项"
            }
            if (wgxall.rows[0].get_electric != 2) {
                i += wgxall.rows[0].get_electric      //4
                if (wgxall.rows[0].get_electric == 1) wgx += " 4项"
            }
            if (wgxall.rows[0].get_firetool != 2) {
                i += wgxall.rows[0].get_firetool      //5
                if (wgxall.rows[0].get_firetool == 1) wgx += " 5项"
            }
            if (wgxall.rows[0].get_saveaway != 2) {
                i += wgxall.rows[0].get_saveaway      //6    
                if (wgxall.rows[0].get_saveaway == 1) wgx += " 6项"
            }
            if (wgxall.rows[0].get_carstop != 2) {
                i += wgxall.rows[0].get_carstop       //7
                if (wgxall.rows[0].get_carstop == 1) wgx += " 7项"
            }
            if (wgxall.rows[0].get_easyfire != 2) {
                i += wgxall.rows[0].get_easyfire      //8
                if (wgxall.rows[0].get_easyfire == 1) wgx += " 8项"
            }
            if (wgxall.rows[0].get_save != 2) {
                i += wgxall.rows[0].get_save          //9
                if (wgxall.rows[0].get_save == 1) wgx += " 9项"
            }
            if (wgxall.rows[0].other != 2) {
                i += wgxall.rows[0].other             //10
                if (wgxall.rows[0].other == 1) wgx += " 10项"
            }
            //根据违规项目判断颜色
            if (i == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 3, note = '符合规范'  WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            } else if (i >= 3 || wgxall.rows[0].get_live == 1) {
                let sql2 = `UPDATE home_base_hx SET ys = 1, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            } else if (i > 0 && i < 3 && wgxall.rows[0].get_live == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 2, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }

        } else if (pj == 4) {
            sql += ` ,get_electric = '${val}'`
            if (!info) sql += `,get_electric_info = NULL `; else sql += `, get_electric_info = '${info}' `;
            if (!pic1 || "") sql += `,get_electric_pic1 = NULL `; sql += `,get_electric_pic1 = '${pic1}' `;
            if (!pic2 || "") sql += `,get_electric_pic2 = NULL `; sql += `,get_electric_pic2 = '${pic2}' `;
            if (!pic3 || "") sql += `,get_electric_pic3 = NULL `; sql += `,get_electric_pic3 = '${pic3}' `;
            if (!pic4 || "") sql += `,get_electric_pic4 = NULL `; sql += `,get_electric_pic4 = '${pic4}' `;
            if (!pic5 || "") sql += `,get_electric_pic5 = NULL `; sql += `,get_electric_pic5 = '${pic5}' `;
            if (!pic6 || "") sql += `,get_electric_pic6 = NULL `; sql += `,get_electric_pic6 = '${pic6}' `;
            sql += ` WHERE id = '${id}'`;
            yield this._daoModel.query(sql);

            //在此处开始根据违规  判断颜色
            let sqlwgx = `SELECT * FROM home_base_hx WHERE id = '${id}' `;
            let wgxall = yield this._daoModel.query(sqlwgx);
            //标记第几项违规
            let wgx = "不符合规范:第"
            // 如果不涉及(2)就不能统计 只统计0 1的
            let i = 0
            if (wgxall.rows[0].get_live != 2) {
                i += wgxall.rows[0].get_live          //1
                if (wgxall.rows[0].get_live == 1) wgx += "1项"
            }
            if (wgxall.rows[0].get_away != 2) {
                i += wgxall.rows[0].get_away          //2 
                if (wgxall.rows[0].get_away == 1) wgx += " 2项"
            }
            if (wgxall.rows[0].get_line != 2) {
                i += wgxall.rows[0].get_line          //3
                if (wgxall.rows[0].get_line == 1) wgx += " 3项"
            }
            if (wgxall.rows[0].get_electric != 2) {
                i += wgxall.rows[0].get_electric      //4
                if (wgxall.rows[0].get_electric == 1) wgx += " 4项"
            }
            if (wgxall.rows[0].get_firetool != 2) {
                i += wgxall.rows[0].get_firetool      //5
                if (wgxall.rows[0].get_firetool == 1) wgx += " 5项"
            }
            if (wgxall.rows[0].get_saveaway != 2) {
                i += wgxall.rows[0].get_saveaway      //6    
                if (wgxall.rows[0].get_saveaway == 1) wgx += " 6项"
            }
            if (wgxall.rows[0].get_carstop != 2) {
                i += wgxall.rows[0].get_carstop       //7
                if (wgxall.rows[0].get_carstop == 1) wgx += " 7项"
            }
            if (wgxall.rows[0].get_easyfire != 2) {
                i += wgxall.rows[0].get_easyfire      //8
                if (wgxall.rows[0].get_easyfire == 1) wgx += " 8项"
            }
            if (wgxall.rows[0].get_save != 2) {
                i += wgxall.rows[0].get_save          //9
                if (wgxall.rows[0].get_save == 1) wgx += " 9项"
            }
            if (wgxall.rows[0].other != 2) {
                i += wgxall.rows[0].other             //10
                if (wgxall.rows[0].other == 1) wgx += " 10项"
            }
            //根据违规项目判断颜色
            if (i == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 3, note = '符合规范'  WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            } else if (i >= 3 || wgxall.rows[0].get_live == 1) {
                let sql2 = `UPDATE home_base_hx SET ys = 1, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            } else if (i > 0 && i < 3 && wgxall.rows[0].get_live == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 2, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }

        } else if (pj == 5) {
            sql += ` ,get_firetool = '${val}'`
            if (!info) sql += `,get_firetool_info = NULL `; else sql += `, get_firetool_info = '${info}' `;
            if (!pic1 || "") sql += `,get_firetool_pic1 = NULL `; sql += `,get_firetool_pic1 = '${pic1}' `;
            if (!pic2 || "") sql += `,get_firetool_pic2 = NULL `; sql += `,get_firetool_pic2 = '${pic2}' `;
            if (!pic3 || "") sql += `,get_firetool_pic3 = NULL `; sql += `,get_firetool_pic3 = '${pic3}' `;
            if (!pic4 || "") sql += `,get_firetool_pic4 = NULL `; sql += `,get_firetool_pic4 = '${pic4}' `;
            if (!pic5 || "") sql += `,get_firetool_pic5 = NULL `; sql += `,get_firetool_pic5 = '${pic5}' `;
            if (!pic6 || "") sql += `,get_firetool_pic6 = NULL `; sql += `,get_firetool_pic6 = '${pic6}' `;
            sql += ` WHERE id = '${id}'`;
            yield this._daoModel.query(sql);

            //在此处开始根据违规  判断颜色
            let sqlwgx = `SELECT * FROM home_base_hx WHERE id = '${id}' `;
            let wgxall = yield this._daoModel.query(sqlwgx);
            //标记第几项违规
            let wgx = "不符合规范:第"
            // 如果不涉及(2)就不能统计 只统计0 1的
            let i = 0
            if (wgxall.rows[0].get_live != 2) {
                i += wgxall.rows[0].get_live          //1
                if (wgxall.rows[0].get_live == 1) wgx += "1项"
            }
            if (wgxall.rows[0].get_away != 2) {
                i += wgxall.rows[0].get_away          //2 
                if (wgxall.rows[0].get_away == 1) wgx += " 2项"
            }
            if (wgxall.rows[0].get_line != 2) {
                i += wgxall.rows[0].get_line          //3
                if (wgxall.rows[0].get_line == 1) wgx += " 3项"
            }
            if (wgxall.rows[0].get_electric != 2) {
                i += wgxall.rows[0].get_electric      //4
                if (wgxall.rows[0].get_electric == 1) wgx += " 4项"
            }
            if (wgxall.rows[0].get_firetool != 2) {
                i += wgxall.rows[0].get_firetool      //5
                if (wgxall.rows[0].get_firetool == 1) wgx += " 5项"
            }
            if (wgxall.rows[0].get_saveaway != 2) {
                i += wgxall.rows[0].get_saveaway      //6    
                if (wgxall.rows[0].get_saveaway == 1) wgx += " 6项"
            }
            if (wgxall.rows[0].get_carstop != 2) {
                i += wgxall.rows[0].get_carstop       //7
                if (wgxall.rows[0].get_carstop == 1) wgx += " 7项"
            }
            if (wgxall.rows[0].get_easyfire != 2) {
                i += wgxall.rows[0].get_easyfire      //8
                if (wgxall.rows[0].get_easyfire == 1) wgx += " 8项"
            }
            if (wgxall.rows[0].get_save != 2) {
                i += wgxall.rows[0].get_save          //9
                if (wgxall.rows[0].get_save == 1) wgx += " 9项"
            }
            if (wgxall.rows[0].other != 2) {
                i += wgxall.rows[0].other             //10
                if (wgxall.rows[0].other == 1) wgx += " 10项"
            }
            //根据违规项目判断颜色
            if (i == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 3, note = '符合规范'  WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            } else if (i >= 3 || wgxall.rows[0].get_live == 1) {
                let sql2 = `UPDATE home_base_hx SET ys = 1, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            } else if (i > 0 && i < 3 && wgxall.rows[0].get_live == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 2, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }

        } else if (pj == 6) {
            ;
            sql += ` ,get_saveaway = '${val}'`
            if (!info) sql += `,get_saveaway_info = NULL `; else sql += `,get_saveaway_info = '${info}' `;
            sql += `,get_saveaway_pic1 = '${pic1}' `;
            sql += `,get_saveaway_pic2 = '${pic2}' `;
            sql += `,get_saveaway_pic3 = '${pic3}' `;
            sql += `,get_saveaway_pic4 = '${pic4}' `;
            sql += `,get_saveaway_pic5 = '${pic5}' `;
            sql += `,get_saveaway_pic6 = '${pic6}' `;
            sql += ` WHERE id = '${id}'`;
            yield this._daoModel.query(sql);

            //在此处开始根据违规  判断颜色
            let sqlwgx = `SELECT * FROM home_base_hx WHERE id = '${id}' `;
            let wgxall = yield this._daoModel.query(sqlwgx);
            //标记第几项违规
            let wgx = "不符合规范:第"
            // 如果不涉及(2)就不能统计 只统计0 1的
            let i = 0
            if (wgxall.rows[0].get_live != 2) {
                i += wgxall.rows[0].get_live          //1
                if (wgxall.rows[0].get_live == 1) wgx += "1项"
            }
            if (wgxall.rows[0].get_away != 2) {
                i += wgxall.rows[0].get_away          //2 
                if (wgxall.rows[0].get_away == 1) wgx += " 2项"
            }
            if (wgxall.rows[0].get_line != 2) {
                i += wgxall.rows[0].get_line          //3
                if (wgxall.rows[0].get_line == 1) wgx += " 3项"
            }
            if (wgxall.rows[0].get_electric != 2) {
                i += wgxall.rows[0].get_electric      //4
                if (wgxall.rows[0].get_electric == 1) wgx += " 4项"
            }
            if (wgxall.rows[0].get_firetool != 2) {
                i += wgxall.rows[0].get_firetool      //5
                if (wgxall.rows[0].get_firetool == 1) wgx += " 5项"
            }
            if (wgxall.rows[0].get_saveaway != 2) {
                i += wgxall.rows[0].get_saveaway      //6    
                if (wgxall.rows[0].get_saveaway == 1) wgx += " 6项"
            }
            if (wgxall.rows[0].get_carstop != 2) {
                i += wgxall.rows[0].get_carstop       //7
                if (wgxall.rows[0].get_carstop == 1) wgx += " 7项"
            }
            if (wgxall.rows[0].get_easyfire != 2) {
                i += wgxall.rows[0].get_easyfire      //8
                if (wgxall.rows[0].get_easyfire == 1) wgx += " 8项"
            }
            if (wgxall.rows[0].get_save != 2) {
                i += wgxall.rows[0].get_save          //9
                if (wgxall.rows[0].get_save == 1) wgx += " 9项"
            }
            if (wgxall.rows[0].other != 2) {
                i += wgxall.rows[0].other             //10
                if (wgxall.rows[0].other == 1) wgx += " 10项"
            }
            //根据违规项目判断颜色
            if (i == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 3, note = '符合规范'  WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            } else if (i >= 3 || wgxall.rows[0].get_live == 1) {
                let sql2 = `UPDATE home_base_hx SET ys = 1, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            } else if (i > 0 && i < 3 && wgxall.rows[0].get_live == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 2, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }

        } else if (pj == 7) {
            sql += ` ,get_carstop = '${val}'`;
            if (!info) sql += `,get_carstop_info = NULL `; else sql += ` , get_carstop_info = '${info}' `;
            sql += `,get_carstop_pic1 = '${pic1}' `;
            sql += `,get_carstop_pic2 = '${pic2}' `;
            sql += `,get_carstop_pic3 = '${pic3}' `;
            sql += `,get_carstop_pic4 = '${pic4}' `;
            sql += `,get_carstop_pic5 = '${pic5}' `;
            sql += `,get_carstop_pic6 = '${pic6}' `;
            sql += ` WHERE id = '${id}'`;
            yield this._daoModel.query(sql);

            //在此处开始根据违规  判断颜色
            let sqlwgx = `SELECT * FROM home_base_hx WHERE id = '${id}' `;
            let wgxall = yield this._daoModel.query(sqlwgx);
            //标记第几项违规
            let wgx = "不符合规范:第"
            // 如果不涉及(2)就不能统计 只统计0 1的
            let i = 0
            if (wgxall.rows[0].get_live != 2) {
                i += wgxall.rows[0].get_live          //1
                if (wgxall.rows[0].get_live == 1) wgx += "1项"
            }
            if (wgxall.rows[0].get_away != 2) {
                i += wgxall.rows[0].get_away          //2 
                if (wgxall.rows[0].get_away == 1) wgx += " 2项"
            }
            if (wgxall.rows[0].get_line != 2) {
                i += wgxall.rows[0].get_line          //3
                if (wgxall.rows[0].get_line == 1) wgx += " 3项"
            }
            if (wgxall.rows[0].get_electric != 2) {
                i += wgxall.rows[0].get_electric      //4
                if (wgxall.rows[0].get_electric == 1) wgx += " 4项"
            }
            if (wgxall.rows[0].get_firetool != 2) {
                i += wgxall.rows[0].get_firetool      //5
                if (wgxall.rows[0].get_firetool == 1) wgx += " 5项"
            }
            if (wgxall.rows[0].get_saveaway != 2) {
                i += wgxall.rows[0].get_saveaway      //6    
                if (wgxall.rows[0].get_saveaway == 1) wgx += " 6项"
            }
            if (wgxall.rows[0].get_carstop != 2) {
                i += wgxall.rows[0].get_carstop       //7
                if (wgxall.rows[0].get_carstop == 1) wgx += " 7项"
            }
            if (wgxall.rows[0].get_easyfire != 2) {
                i += wgxall.rows[0].get_easyfire      //8
                if (wgxall.rows[0].get_easyfire == 1) wgx += " 8项"
            }
            if (wgxall.rows[0].get_save != 2) {
                i += wgxall.rows[0].get_save          //9
                if (wgxall.rows[0].get_save == 1) wgx += " 9项"
            }
            if (wgxall.rows[0].other != 2) {
                i += wgxall.rows[0].other             //10
                if (wgxall.rows[0].other == 1) wgx += " 10项"
            }
            //根据违规项目判断颜色
            if (i == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 3, note = '符合规范'  WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            } else if (i >= 3 || wgxall.rows[0].get_live == 1) {
                let sql2 = `UPDATE home_base_hx SET ys = 1, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            } else if (i > 0 && i < 3 && wgxall.rows[0].get_live == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 2, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }

        } else if (pj == 8) {
            sql += ` ,get_easyfire = '${val}'`
            if (!info) sql += `,get_easyfire_info = NULL `; else sql += `, get_easyfire_info = '${info}' `;
            sql += `,get_easyfire_pic1 = '${pic1}' `;
            sql += `,get_easyfire_pic2 = '${pic2}' `;
            sql += `,get_easyfire_pic3 = '${pic3}' `;
            sql += `,get_easyfire_pic4 = '${pic4}' `;
            sql += `,get_easyfire_pic5 = '${pic5}' `;
            sql += `,get_easyfire_pic6 = '${pic6}' `;
            sql += ` WHERE id = '${id}'`;
            yield this._daoModel.query(sql);

            //在此处开始根据违规  判断颜色
            let sqlwgx = `SELECT * FROM home_base_hx WHERE id = '${id}' `;
            let wgxall = yield this._daoModel.query(sqlwgx);
            //标记第几项违规
            let wgx = "不符合规范:第"
            // 如果不涉及(2)就不能统计 只统计0 1的
            let i = 0
            if (wgxall.rows[0].get_live != 2) {
                i += wgxall.rows[0].get_live          //1
                if (wgxall.rows[0].get_live == 1) wgx += "1项"
            }
            if (wgxall.rows[0].get_away != 2) {
                i += wgxall.rows[0].get_away          //2 
                if (wgxall.rows[0].get_away == 1) wgx += " 2项"
            }
            if (wgxall.rows[0].get_line != 2) {
                i += wgxall.rows[0].get_line          //3
                if (wgxall.rows[0].get_line == 1) wgx += " 3项"
            }
            if (wgxall.rows[0].get_electric != 2) {
                i += wgxall.rows[0].get_electric      //4
                if (wgxall.rows[0].get_electric == 1) wgx += " 4项"
            }
            if (wgxall.rows[0].get_firetool != 2) {
                i += wgxall.rows[0].get_firetool      //5
                if (wgxall.rows[0].get_firetool == 1) wgx += " 5项"
            }
            if (wgxall.rows[0].get_saveaway != 2) {
                i += wgxall.rows[0].get_saveaway      //6    
                if (wgxall.rows[0].get_saveaway == 1) wgx += " 6项"
            }
            if (wgxall.rows[0].get_carstop != 2) {
                i += wgxall.rows[0].get_carstop       //7
                if (wgxall.rows[0].get_carstop == 1) wgx += " 7项"
            }
            if (wgxall.rows[0].get_easyfire != 2) {
                i += wgxall.rows[0].get_easyfire      //8
                if (wgxall.rows[0].get_easyfire == 1) wgx += " 8项"
            }
            if (wgxall.rows[0].get_save != 2) {
                i += wgxall.rows[0].get_save          //9
                if (wgxall.rows[0].get_save == 1) wgx += " 9项"
            }
            if (wgxall.rows[0].other != 2) {
                i += wgxall.rows[0].other             //10
                if (wgxall.rows[0].other == 1) wgx += " 10项"
            }
            //根据违规项目判断颜色
            if (i == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 3, note = '符合规范'  WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            } else if (i >= 3 || wgxall.rows[0].get_live == 1) {
                let sql2 = `UPDATE home_base_hx SET ys = 1, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            } else if (i > 0 && i < 3 && wgxall.rows[0].get_live == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 2, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }

        } else if (pj == 9) {
            sql += ` ,get_save = '${val}'`
            if (!info) sql += `,get_save_info = NULL `; else sql += `, get_save_info = '${info}' `;
            sql += `,get_save_pic1 = '${pic1}' `;
            sql += `,get_save_pic2 = '${pic2}' `;
            sql += `,get_save_pic3 = '${pic3}' `;
            sql += `,get_save_pic4 = '${pic4}' `;
            sql += `,get_save_pic5 = '${pic5}' `;
            sql += `,get_save_pic6 = '${pic6}' `;
            sql += ` WHERE id = '${id}'`;
            yield this._daoModel.query(sql);

            //在此处开始根据违规  判断颜色
            let sqlwgx = `SELECT * FROM home_base_hx WHERE id = '${id}' `;
            let wgxall = yield this._daoModel.query(sqlwgx);
            //标记第几项违规
            let wgx = "不符合规范:第"
            // 如果不涉及(2)就不能统计 只统计0 1的
            let i = 0
            if (wgxall.rows[0].get_live != 2) {
                i += wgxall.rows[0].get_live          //1
                if (wgxall.rows[0].get_live == 1) wgx += "1项"
            }
            if (wgxall.rows[0].get_away != 2) {
                i += wgxall.rows[0].get_away          //2 
                if (wgxall.rows[0].get_away == 1) wgx += " 2项"
            }
            if (wgxall.rows[0].get_line != 2) {
                i += wgxall.rows[0].get_line          //3
                if (wgxall.rows[0].get_line == 1) wgx += " 3项"
            }
            if (wgxall.rows[0].get_electric != 2) {
                i += wgxall.rows[0].get_electric      //4
                if (wgxall.rows[0].get_electric == 1) wgx += " 4项"
            }
            if (wgxall.rows[0].get_firetool != 2) {
                i += wgxall.rows[0].get_firetool      //5
                if (wgxall.rows[0].get_firetool == 1) wgx += " 5项"
            }
            if (wgxall.rows[0].get_saveaway != 2) {
                i += wgxall.rows[0].get_saveaway      //6    
                if (wgxall.rows[0].get_saveaway == 1) wgx += " 6项"
            }
            if (wgxall.rows[0].get_carstop != 2) {
                i += wgxall.rows[0].get_carstop       //7
                if (wgxall.rows[0].get_carstop == 1) wgx += " 7项"
            }
            if (wgxall.rows[0].get_easyfire != 2) {
                i += wgxall.rows[0].get_easyfire      //8
                if (wgxall.rows[0].get_easyfire == 1) wgx += " 8项"
            }
            if (wgxall.rows[0].get_save != 2) {
                i += wgxall.rows[0].get_save          //9
                if (wgxall.rows[0].get_save == 1) wgx += " 9项"
            }
            if (wgxall.rows[0].other != 2) {
                i += wgxall.rows[0].other             //10
                if (wgxall.rows[0].other == 1) wgx += " 10项"
            }
            //根据违规项目判断颜色
            if (i == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 3, note = '符合规范'  WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            } else if (i >= 3 || wgxall.rows[0].get_live == 1) {
                let sql2 = `UPDATE home_base_hx SET ys = 1, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            } else if (i > 0 && i < 3 && wgxall.rows[0].get_live == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 2, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }

        } else {
            islast = 1;//最后一步修改
            sql += ` ,other = '${val}'`;
            if (!info) sql += `,other_info = NULL `; else sql += `, other_info = '${info}' `;
            sql += `,other_pic1 = '${pic1}' `;
            sql += `,other_pic2 = '${pic2}' `;
            sql += `,other_pic3 = '${pic3}' `;
            sql += `,other_pic4 = '${pic4}' `;
            sql += `,other_pic5 = '${pic5}' `;
            sql += `,other_pic6 = '${pic6}' `;
            sql += ` WHERE id = '${id}'`;
            yield this._daoModel.query(sql);


            //在此处开始根据违规  判断颜色
            let sqlwgx = `SELECT * FROM home_base_hx WHERE id = '${id}' `;
            let wgxall = yield this._daoModel.query(sqlwgx);
            //标记第几项违规
            let wgx = "不符合规范:第"
            // 如果不涉及(2)就不能统计 只统计0 1的
            let i = 0
            if (wgxall.rows[0].get_live != 2) {
                i += wgxall.rows[0].get_live          //1
                if (wgxall.rows[0].get_live == 1) wgx += "1项"
            }
            if (wgxall.rows[0].get_away != 2) {
                i += wgxall.rows[0].get_away          //2 
                if (wgxall.rows[0].get_away == 1) wgx += " 2项"
            }
            if (wgxall.rows[0].get_line != 2) {
                i += wgxall.rows[0].get_line          //3
                if (wgxall.rows[0].get_line == 1) wgx += " 3项"
            }
            if (wgxall.rows[0].get_electric != 2) {
                i += wgxall.rows[0].get_electric      //4
                if (wgxall.rows[0].get_electric == 1) wgx += " 4项"
            }
            if (wgxall.rows[0].get_firetool != 2) {
                i += wgxall.rows[0].get_firetool      //5
                if (wgxall.rows[0].get_firetool == 1) wgx += " 5项"
            }
            if (wgxall.rows[0].get_saveaway != 2) {
                i += wgxall.rows[0].get_saveaway      //6    
                if (wgxall.rows[0].get_saveaway == 1) wgx += " 6项"
            }
            if (wgxall.rows[0].get_carstop != 2) {
                i += wgxall.rows[0].get_carstop       //7
                if (wgxall.rows[0].get_carstop == 1) wgx += " 7项"
            }
            if (wgxall.rows[0].get_easyfire != 2) {
                i += wgxall.rows[0].get_easyfire      //8
                if (wgxall.rows[0].get_easyfire == 1) wgx += " 8项"
            }
            if (wgxall.rows[0].get_save != 2) {
                i += wgxall.rows[0].get_save          //9
                if (wgxall.rows[0].get_save == 1) wgx += " 9项"
            }
            if (wgxall.rows[0].other != 2) {
                i += wgxall.rows[0].other             //10
                if (wgxall.rows[0].other == 1) wgx += " 10项"
            }
            //根据违规项目判断颜色
            if (i == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 3, note = '符合规范'  WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            } else if (i >= 3 || wgxall.rows[0].get_live == 1) {
                let sql2 = `UPDATE home_base_hx SET ys = 1, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            } else if (i > 0 && i < 3 && wgxall.rows[0].get_live == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 2, note = '${wgx}'   WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
            }

        }



        let queryByid = `select * from home_base_hx where id = '${id}'`;
        let hxByid = yield this._daoModel.query(queryByid);
        r = hxByid.rows

        let queryHb = `select name from home_base where id = '${pid}'`;
        let resulthb = yield this._daoModel.query(queryHb);

        let hbName = resulthb.rows[0].name;
        return {
            code: 1,
            successed: true,
            rows: r,
            hbName, hbName
        }
    }


    * qrtj(req, res) {

        let id = req.body.id;
        let pid = req.body.pid;
        let r = {};
        let sqlwgx = `SELECT * FROM home_base_hx WHERE id = '${id}' `;
        let wgxall = yield this._daoModel.query(sqlwgx);

        //标记第几项违规
        let wgx = "不符合规范:第"
        // 如果不涉及(2)就不能统计 只统计0 1的
        let i = 0
        if (wgxall.rows[0].get_live != 2) {
            i += wgxall.rows[0].get_live          //1
            if (wgxall.rows[0].get_live == 1) wgx += "1项"

        }
        if (wgxall.rows[0].get_away != 2) {
            i += wgxall.rows[0].get_away          //2 
            if (wgxall.rows[0].get_away == 1) wgx += " 2项"
        }

        if (wgxall.rows[0].get_line != 2) {
            i += wgxall.rows[0].get_line          //3
            if (wgxall.rows[0].get_line == 1) wgx += " 3项"
        }

        if (wgxall.rows[0].get_electric != 2) {
            i += wgxall.rows[0].get_electric      //4
            if (wgxall.rows[0].get_electric == 1) wgx += " 4项"
        }

        if (wgxall.rows[0].get_firetool != 2) {
            i += wgxall.rows[0].get_firetool      //5
            if (wgxall.rows[0].get_firetool == 1) wgx += " 5项"
        }

        if (wgxall.rows[0].get_saveaway != 2) {
            i += wgxall.rows[0].get_saveaway      //6    
            if (wgxall.rows[0].get_saveaway == 1) wgx += " 6项"
        }

        if (wgxall.rows[0].get_carstop != 2) {
            i += wgxall.rows[0].get_carstop       //7
            if (wgxall.rows[0].get_carstop == 1) wgx += " 7项"
        }

        if (wgxall.rows[0].get_easyfire != 2) {
            i += wgxall.rows[0].get_easyfire      //8
            if (wgxall.rows[0].get_easyfire == 1) wgx += " 8项"
        }

        if (wgxall.rows[0].get_save != 2) {
            i += wgxall.rows[0].get_save          //9
            if (wgxall.rows[0].get_save == 1) wgx += " 9项"
        }

        if (wgxall.rows[0].other != 2) {
            i += wgxall.rows[0].other             //10
            if (wgxall.rows[0].other == 1) wgx += " 10项"
        }

        // 1.检查未发现隐患问题的（检查项全部为否）风险等级判定为绿色。
        // 2.存在违规住人或者3项以上（含）隐患问题的风险等级判定为红色。
        // 3.其余情况风险等级判定为黄色。
        if (i == 0) {
            let sql2 = `UPDATE home_base_hx SET ys = 3, note = '符合规范'  WHERE id = '${id}' `;
            yield this._daoModel.query(sql2);
            //let hbSql = `UPDATE home_base SET ys = 3, note = '符合规范'  WHERE id = '${pid}'` ;
            //yield this._daoModel.query(hbSql);
        } else if (i >= 3 || wgxall.rows[0].get_live == 1) {
            let sql2 = `UPDATE home_base_hx SET ys = 1, note = '${wgx}'   WHERE id = '${id}' `;
            yield this._daoModel.query(sql2);
            //let hbSql = `UPDATE home_base SET ys = 1, note = '${wgx}'   WHERE id = '${pid}'` ;
            //yield this._daoModel.query(hbSql);
        } else if (i > 0 && i < 3 && wgxall.rows[0].get_live == 0) {
            let sql2 = `UPDATE home_base_hx SET ys = 2, note = '${wgx}'   WHERE id = '${id}' `;
            yield this._daoModel.query(sql2);
            //let hbSql = `UPDATE home_base SET ys = 2, note = '${wgx}'   WHERE id = '${pid}'` ;
            //yield this._daoModel.query(hbSql);
        }
        let queryByid = `select * from home_base_hx where id = '${id}'`;
        let hxByid = yield this._daoModel.query(queryByid);
        r = hxByid.rows

        let queryHb = `select name from home_base where id = '${pid}'`;
        let resulthb = yield this._daoModel.query(queryHb);

        let hbName = resulthb.rows[0].name;
        return {
            code: 1,
            successed: true,
            rows: r,
            hbName, hbName
        }
    }

    * reUpdateHx(req, res) {
        let r = {};
        let id = req.body.id;
        let pj = req.body.pj;
        let val = req.body.val;
        let info = req.body.info;
        let pic1 = req.body.pic1;
        let pic2 = req.body.pic2;
        let pic3 = req.body.pic3;
        let pic4 = req.body.pic4;
        let pic5 = req.body.pic5;
        let pic6 = req.body.pic6;
        let pid = req.body.pid;
        let uid = req.body.uid;
        let a = req.body.a;
        let here = yield this.checkuser(uid, a);
        if (here == 0) {
            return {
                code: -1,
                here: 0,
                successed: true,
                msg: "请重新登陆"
            }
        }

        //默认绿色
        let ys = 3;
        if (!id) {
            return {
                code: 0,
                successed: false,
                msg: "请传hxid"
            }
        }

        // 只要有一项不符合要求就是黄色 ys=2
        if (val == 1) {
            let sql2 = `UPDATE home_base_hx SET violations_num = violations_num+1 WHERE id = '${id}' `;
            yield this._daoModel.query(sql2);
        }

        // 设置更新时间
        let today = date.format(new Date(), 'YYYY-MM-DD HH:mm:ss'); //当前时间

        let sql = `UPDATE home_base_hx SET uid='${uid}', update_time = '${today}', djb = ${pj} `;
        if (pj == 1) {
            sql += ` ,get_live = '${val}' `;
            if (info == null) sql += `,get_live_info = 'NULL' `; else sql += `,get_live_info = '${info}' `;
            if (pic1) sql += `,get_live_pic1 = '${pic1}' `;
            if (pic2) sql += `,get_live_pic2 = '${pic2}' `;
            if (pic3) sql += `,get_live_pic3 = '${pic3}' `;
            if (pic4) sql += `,get_live_pic4 = '${pic4}' `;
            if (pic5) sql += `,get_live_pic5 = '${pic5}' `;
            if (pic6) sql += `,get_live_pic6 = '${pic6}' `;

        } else if (pj == 2) {
            sql += ` ,get_away = '${val}'`
            if (info == null) sql += `,get_away_info = 'NULL' `; else sql += `, get_away_info = '${info}' `;
            if (pic1) sql += `,get_away_pic1 = '${pic1}' `;
            if (pic2) sql += `,get_away_pic2 = '${pic2}' `;
            if (pic3) sql += `,get_away_pic3 = '${pic3}' `;
            if (pic4) sql += `,get_away_pic4 = '${pic4}' `;
            if (pic5) sql += `,get_away_pic5 = '${pic5}' `;
            if (pic6) sql += `,get_away_pic6 = '${pic6}' `;

        } else if (pj == 3) {
            sql += ` ,get_line = '${val}'`
            if (info == null) sql += `,get_line_info = 'NULL' `; else sql += `, get_line_info = '${info}' `;
            if (pic1) sql += `,get_line_pic1 = '${pic1}' `;
            if (pic2) sql += `,get_line_pic2 = '${pic2}' `;
            if (pic3) sql += `,get_line_pic3 = '${pic3}' `;
            if (pic4) sql += `,get_line_pic4 = '${pic4}' `;
            if (pic5) sql += `,get_line_pic5 = '${pic5}' `;
            if (pic6) sql += `,get_line_pic6 = '${pic6}' `;

        } else if (pj == 4) {
            sql += ` ,get_electric = '${val}'`
            if (info == null) sql += `,get_electric_info = 'NULL' `; else sql += `, get_electric_info = '${info}' `;
            if (pic1) sql += `,get_electric_pic1 = '${pic1}' `;
            if (pic2) sql += `,get_electric_pic2 = '${pic2}' `;
            if (pic3) sql += `,get_electric_pic3 = '${pic3}' `;
            if (pic4) sql += `,get_electric_pic4 = '${pic4}' `;
            if (pic5) sql += `,get_electric_pic5 = '${pic5}' `;
            if (pic6) sql += `,get_electric_pic6 = '${pic6}' `;

        } else if (pj == 5) {
            sql += ` ,get_firetool = '${val}'`
            if (info == null) sql += `,get_firetool_info = 'NULL' `; else sql += `, get_firetool_info = '${info}' `;
            if (pic1) sql += `,get_firetool_pic1 = '${pic1}' `;
            if (pic2) sql += `,get_firetool_pic2 = '${pic2}' `;
            if (pic3) sql += `,get_firetool_pic3 = '${pic3}' `;
            if (pic4) sql += `,get_firetool_pic4 = '${pic4}' `;
            if (pic5) sql += `,get_firetool_pic5 = '${pic5}' `;
            if (pic6) sql += `,get_firetool_pic6 = '${pic6}' `;

        } else if (pj == 6) {
            ;
            sql += ` ,get_saveaway = '${val}'`
            if (info == null) sql += `,get_saveaway_info = 'NULL' `; else sql += `,get_saveaway_info = '${info}' `;
            if (pic1) sql += `,get_saveaway_pic1 = '${pic1}' `;
            if (pic2) sql += `,get_saveaway_pic2 = '${pic2}' `;
            if (pic3) sql += `,get_saveaway_pic3 = '${pic3}' `;
            if (pic4) sql += `,get_saveaway_pic4 = '${pic4}' `;
            if (pic5) sql += `,get_saveaway_pic5 = '${pic5}' `;
            if (pic6) sql += `,get_saveaway_pic6 = '${pic6}' `;
        } else if (pj == 7) {
            sql += ` ,get_carstop = '${val}'`;
            if (info == null) sql += `,get_carstop_info = 'NULL' `; else sql += ` , get_carstop_info = '${info}' `;
            if (pic1) sql += `,get_carstop_pic1 = '${pic1}' `;
            if (pic2) sql += `,get_carstop_pic2 = '${pic2}' `;
            if (pic3) sql += `,get_carstop_pic3 = '${pic3}' `;
            if (pic4) sql += `,get_carstop_pic4 = '${pic4}' `;
            if (pic5) sql += `,get_carstop_pic5 = '${pic5}' `;
            if (pic6) sql += `,get_carstop_pic6 = '${pic6}' `;
        } else if (pj == 8) {
            sql += ` ,get_easyfire = '${val}'`
            if (info == null) sql += `,get_easyfire_info = 'NULL' `; else sql += `, get_easyfire_info = '${info}' `;
            if (pic1) sql += `,get_easyfire_pic1 = '${pic1}' `;
            if (pic2) sql += `,get_easyfire_pic2 = '${pic2}' `;
            if (pic3) sql += `,get_easyfire_pic3 = '${pic3}' `;
            if (pic4) sql += `,get_easyfire_pic4 = '${pic4}' `;
            if (pic5) sql += `,get_easyfire_pic5 = '${pic5}' `;
            if (pic6) sql += `,get_easyfire_pic6 = '${pic6}' `;
        } else if (pj == 9) {
            sql += ` ,get_save = '${val}'`
            if (info == null) sql += `,get_save_info = 'NULL' `; else sql += `, get_save_info = '${info}' `;
            if (pic1) sql += `,get_save_pic1 = '${pic1}' `;
            if (pic2) sql += `,get_save_pic2 = '${pic2}' `;
            if (pic3) sql += `,get_save_pic3 = '${pic3}' `;
            if (pic4) sql += `,get_save_pic4 = '${pic4}' `;
            if (pic5) sql += `,get_save_pic5 = '${pic5}' `;
            if (pic6) sql += `,get_save_pic6 = '${pic6}' `;
        } else {
            sql += ` ,other = '${val}'`
            if (info == null) sql += `,other_info = 'NULL' `; else sql += `, other_info = '${info}' `;
            if (pic1) sql += `,other_pic1 = '${pic1}' `;
            if (pic2) sql += `,other_pic2 = '${pic2}' `;
            if (pic3) sql += `,other_pic3 = '${pic3}' `;
            if (pic4) sql += `,other_pic4 = '${pic4}' `;
            if (pic5) sql += `,other_pic5 = '${pic5}' `;
            if (pic6) sql += `,other_pic6 = '${pic6}' `;

            //如果ys字段没有改变过 就可以认为是绿色
            let sql1 = `SELECT violations_num FROM home_base_hx WHERE id = '${id}' `;
            let hx_ys = yield this._daoModel.query(sql1);
            console.log(hx_ys.rows[0].ys);
            if (hx_ys.rows[0].violations_num == 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 3, note = '符合规范' WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
                let hbSql = `UPDATE home_base SET ys = 3, note = '符合规范' WHERE id = '${pid}'`;
                yield this._daoModel.query(hbSql);
            } else if (hx_ys.rows[0].violations_num > 0) {
                let sql2 = `UPDATE home_base_hx SET ys = 2, note = '不符合规范' WHERE id = '${id}' `;
                yield this._daoModel.query(sql2);
                let hbSql = `UPDATE home_base SET ys = 2, note = '不符合规范' WHERE id = '${pid}'`;
                yield this._daoModel.query(hbSql);
            }

        }
        sql += ` WHERE id = '${id}'`;
        let result = yield this._daoModel.query(sql);
        let queryByid = `select * from home_base_hx where id = '${id}'`;
        let hxByid = yield this._daoModel.query(queryByid);
        r = hxByid.rows

        let queryHb = `select name from home_base where id = '${pid}'`;
        let resulthb = yield this._daoModel.query(queryHb);

        let hbName = resulthb.rows[0].name;
        return {
            code: 1,
            successed: true,
            rows: r,
            hbName: hbName
        }
    }

    // * saveShyj1(req, res) {
    //     let r = {};
    //     let id = req.body.id;
    //     let sh_note = req.body.sh_note;
    //     let zg_time = req.body.zg_time;
    //     let sql = `update home_base_hx set sh_note = '${sh_note}', zg_time = '${zg_time}' where id = '${id}'`  ;
    //     let result = yield this._daoModel.query(sql);
    //     let hxsql = `select update_time, pid from home_base_hx where id= '${id}'`;
    //     let hxdetail = yield this._daoModel.query(hxsql);
    //     let hxupdate_time = hxdetail.rows[0].update_time;
    //     let pid = hxdetail.rows[0].pid;
    //     // 为hb插入新的时间
    //     let hbsql = `update home_base set sh_time = '${hxupdate_time}', zg_time = '${zg_time}' where id = '${pid}' `;
    //     yield this._daoModel.query(hbsql);
    //     r   = result.rows;
    //     r.sh_note = sh_note;
    //     r.zg_time = req.body.zg_time;
    //     return {
    //         code: 1,
    //         successed: true,
    //         rows: r
    //     }
    // }

    * getHxById(req, res) {
        let r = {};
        let id = req.params.id;
        let sql = `SELECT * FROM home_base_hx WHERE id = ` + id;
        let result = yield this._daoModel.query(sql);
        r = result.rows

        return {
            code: 1,
            successed: true,
            rows: r
        }
    }


    * getHxByPid(req, res) {
        let r = {};
        let pid = req.params.pid;
        let sql = 'SELECT * FROM home_base_hx WHERE pid = ' + pid + ' order by id desc';
        let result = yield this._daoModel.query(sql);
        result.rows.map((item, index) => {
            if (item.get_live_pic1 && item.get_live_pic1.indexOf('http') == -1) {
                item.get_live_pic1 = config.appsetting.picHead + item.get_live_pic1;
            }
            if (item.get_live_pic2 && item.get_live_pic2.indexOf('http') == -1) {
                item.get_live_pic2 = config.appsetting.picHead + item.get_live_pic2;
            }
            if (item.get_live_pic3 && item.get_live_pic3.indexOf('http') == -1) {
                item.get_live_pic3 = config.appsetting.picHead + item.get_live_pic3;
            }
            if (item.get_live_pic4 && item.get_live_pic4.indexOf('http') == -1) {
                item.get_live_pic4 = config.appsetting.picHead + item.get_live_pic4;
            }
            if (item.get_live_pic5 && item.get_live_pic5.indexOf('http') == -1) {
                item.get_live_pic5 = config.appsetting.picHead + item.get_live_pic5;
            }
            if (item.get_live_pic6 && item.get_live_pic6.indexOf('http') == -1) {
                item.get_live_pic6 = config.appsetting.picHead + item.get_live_pic6;
            }

            if (item.get_away_pic1 && item.get_away_pic1.indexOf('http') == -1) {
                item.get_away_pic1 = config.appsetting.picHead + item.get_away_pic1;
            }
            if (item.get_away_pic2 && item.get_away_pic2.indexOf('http') == -1) {
                item.get_away_pic2 = config.appsetting.picHead + item.get_away_pic2;
            }
            if (item.get_away_pic3 && item.get_away_pic3.indexOf('http') == -1) {
                item.get_away_pic3 = config.appsetting.picHead + item.get_away_pic3;
            }
            if (item.get_away_pic4 && item.get_away_pic4.indexOf('http') == -1) {
                item.get_away_pic4 = config.appsetting.picHead + item.get_away_pic4;
            }
            if (item.get_away_pic5 && item.get_away_pic5.indexOf('http') == -1) {
                item.get_away_pic5 = config.appsetting.picHead + item.get_away_pic5;
            }
            if (item.get_away_pic6 && item.get_away_pic6.indexOf('http') == -1) {
                item.get_away_pic6 = config.appsetting.picHead + item.get_away_pic6;
            }

            if (item.get_line_pic1 && item.get_line_pic1.indexOf('http') == -1) {
                item.get_line_pic1 = config.appsetting.picHead + item.get_line_pic1;
            }
            if (item.get_line_pic2 && item.get_line_pic2.indexOf('http') == -1) {
                item.get_line_pic2 = config.appsetting.picHead + item.get_line_pic2;
            }
            if (item.get_line_pic3 && item.get_line_pic3.indexOf('http') == -1) {
                item.get_line_pic3 = config.appsetting.picHead + item.get_line_pic3;
            }
            if (item.get_line_pic4 && item.get_line_pic4.indexOf('http') == -1) {
                item.get_line_pic4 = config.appsetting.picHead + item.get_line_pic4;
            }
            if (item.get_line_pic5 && item.get_line_pic5.indexOf('http') == -1) {
                item.get_line_pic5 = config.appsetting.picHead + item.get_line_pic5;
            }
            if (item.get_line_pic6 && item.get_line_pic6.indexOf('http') == -1) {
                item.get_line_pic6 = config.appsetting.picHead + item.get_line_pic6;
            }


            if (item.get_electric_pic1 && item.get_electric_pic1.indexOf('http') == -1) {
                item.get_electric_pic1 = config.appsetting.picHead + item.get_electric_pic1;
            }
            if (item.get_electric_pic2 && item.get_electric_pic2.indexOf('http') == -1) {
                item.get_electric_pic2 = config.appsetting.picHead + item.get_electric_pic2;
            }
            if (item.get_electric_pic3 && item.get_electric_pic3.indexOf('http') == -1) {
                item.get_electric_pic3 = config.appsetting.picHead + item.get_electric_pic3;
            }
            if (item.get_electric_pic4 && item.get_electric_pic4.indexOf('http') == -1) {
                item.get_electric_pic4 = config.appsetting.picHead + item.get_electric_pic4;
            }
            if (item.get_electric_pic5 && item.get_electric_pic5.indexOf('http') == -1) {
                item.get_electric_pic5 = config.appsetting.picHead + item.get_electric_pic5;
            }
            if (item.get_electric_pic6 && item.get_electric_pic6.indexOf('http') == -1) {
                item.get_electric_pic6 = config.appsetting.picHead + item.get_electric_pic6;
            }

            if (item.get_firetool_pic1 && item.get_firetool_pic1.indexOf('http') == -1) {
                item.get_firetool_pic1 = config.appsetting.picHead + item.get_firetool_pic1;
            }
            if (item.get_firetool_pic2 && item.get_firetool_pic2.indexOf('http') == -1) {
                item.get_firetool_pic2 = config.appsetting.picHead + item.get_firetool_pic2;
            }
            if (item.get_firetool_pic3 && item.get_firetool_pic3.indexOf('http') == -1) {
                item.get_firetool_pic3 = config.appsetting.picHead + item.get_firetool_pic3;
            }
            if (item.get_firetool_pic4 && item.get_firetool_pic4.indexOf('http') == -1) {
                item.get_firetool_pic4 = config.appsetting.picHead + item.get_firetool_pic4;
            }
            if (item.get_firetool_pic5 && item.get_firetool_pic5.indexOf('http') == -1) {
                item.get_firetool_pic5 = config.appsetting.picHead + item.get_firetool_pic5;
            }
            if (item.get_firetool_pic6 && item.get_firetool_pic6.indexOf('http') == -1) {
                item.get_firetool_pic6 = config.appsetting.picHead + item.get_firetool_pic6;
            }

            if (item.get_saveaway_pic1 && item.get_saveaway_pic1.indexOf('http') == -1) {
                item.get_saveaway_pic1 = config.appsetting.picHead + item.get_saveaway_pic1;
            }
            if (item.get_saveaway_pic2 && item.get_saveaway_pic2.indexOf('http') == -1) {
                item.get_saveaway_pic2 = config.appsetting.picHead + item.get_saveaway_pic2;
            }
            if (item.get_saveaway_pic3 && item.get_saveaway_pic3.indexOf('http') == -1) {
                item.get_saveaway_pic3 = config.appsetting.picHead + item.get_saveaway_pic3;
            }
            if (item.get_saveaway_pic4 && item.get_saveaway_pic4.indexOf('http') == -1) {
                item.get_saveaway_pic4 = config.appsetting.picHead + item.get_saveaway_pic4;
            }
            if (item.get_saveaway_pic5 && item.get_saveaway_pic5.indexOf('http') == -1) {
                item.get_saveaway_pic5 = config.appsetting.picHead + item.get_saveaway_pic5;
            }
            if (item.get_saveaway_pic6 && item.get_saveaway_pic6.indexOf('http') == -1) {
                item.get_saveaway_pic6 = config.appsetting.picHead + item.get_saveaway_pic6;
            }

            if (item.get_carstop_pic1 && item.get_carstop_pic1.indexOf('http') == -1) {
                item.get_carstop_pic1 = config.appsetting.picHead + item.get_carstop_pic1;
            }
            if (item.get_carstop_pic2 && item.get_carstop_pic2.indexOf('http') == -1) {
                item.get_carstop_pic2 = config.appsetting.picHead + item.get_carstop_pic2;
            }

            if (item.get_carstop_pic3 && item.get_carstop_pic3.indexOf('http') == -1) {
                item.get_carstop_pic3 = config.appsetting.picHead + item.get_carstop_pic3;
            }

            if (item.get_carstop_pic4 && item.get_carstop_pic4.indexOf('http') == -1) {
                item.get_carstop_pic4 = config.appsetting.picHead + item.get_carstop_pic4;
            }

            if (item.get_carstop_pic5 && item.get_carstop_pic5.indexOf('http') == -1) {
                item.get_carstop_pic5 = config.appsetting.picHead + item.get_carstop_pic5;
            }
            if (item.get_carstop_pic6 && item.get_carstop_pic6.indexOf('http') == -1) {
                item.get_carstop_pic6 = config.appsetting.picHead + item.get_carstop_pic6;
            }


            if (item.get_easyfire_pic1 && item.get_easyfire_pic1.indexOf('http') == -1) {
                item.get_easyfire_pic1 = config.appsetting.picHead + item.get_easyfire_pic1;
            }
            if (item.get_easyfire_pic2 && item.get_easyfire_pic2.indexOf('http') == -1) {
                item.get_easyfire_pic2 = config.appsetting.picHead + item.get_easyfire_pic2;
            }
            if (item.get_easyfire_pic3 && item.get_easyfire_pic3.indexOf('http') == -1) {
                item.get_easyfire_pic3 = config.appsetting.picHead + item.get_easyfire_pic3;
            }
            if (item.get_easyfire_pic4 && item.get_easyfire_pic4.indexOf('http') == -1) {
                item.get_easyfire_pic4 = config.appsetting.picHead + item.get_easyfire_pic4;
            }
            if (item.get_easyfire_pic5 && item.get_easyfire_pic5.indexOf('http') == -1) {
                item.get_easyfire_pic5 = config.appsetting.picHead + item.get_easyfire_pic5;
            }
            if (item.get_easyfire_pic6 && item.get_easyfire_pic6.indexOf('http') == -1) {
                item.get_easyfire_pic6 = config.appsetting.picHead + item.get_easyfire_pic6;
            }

            if (item.get_save_pic1 && item.get_save_pic1.indexOf('http') == -1) {
                item.get_save_pic1 = config.appsetting.picHead + item.get_save_pic1;
            }
            if (item.get_save_pic2 && item.get_save_pic2.indexOf('http') == -1) {
                item.get_save_pic2 = config.appsetting.picHead + item.get_save_pic2;
            }
            if (item.get_save_pic2 && item.get_save_pic2.indexOf('http') == -1) {
                item.get_save_pic2 = config.appsetting.picHead + item.get_save_pic2;
            }
            if (item.get_save_pic3 && item.get_save_pic3.indexOf('http') == -1) {
                item.get_save_pic3 = config.appsetting.picHead + item.get_save_pic3;
            }
            if (item.get_save_pic4 && item.get_save_pic4.indexOf('http') == -1) {
                item.get_save_pic4 = config.appsetting.picHead + item.get_save_pic4;
            }
            if (item.get_save_pic5 && item.get_save_pic5.indexOf('http') == -1) {
                item.get_save_pic5 = config.appsetting.picHead + item.get_save_pic5;
            }
            if (item.get_save_pic6 && item.get_save_pic6.indexOf('http') == -1) {
                item.get_save_pic6 = config.appsetting.picHead + item.get_save_pic6;
            }

            if (item.other_pic1 && item.other_pic1.indexOf('http') == -1) {
                item.other_pic1 = config.appsetting.picHead + item.other_pic1;
            }
            if (item.other_pic2 && item.other_pic2.indexOf('http') == -1) {
                item.other_pic2 = config.appsetting.picHead + item.other_pic2;
            }
            if (item.other_pic3 && item.other_pic3.indexOf('http') == -1) {
                item.other_pic3 = config.appsetting.picHead + item.other_pic3;
            }
            if (item.other_pic4 && item.other_pic4.indexOf('http') == -1) {
                item.other_pic4 = config.appsetting.picHead + item.other_pic4;
            }
            if (item.other_pic5 && item.other_pic5.indexOf('http') == -1) {
                item.other_pic5 = config.appsetting.picHead + item.other_pic5;
            }
            if (item.other_pic6 && item.other_pic6.indexOf('http') == -1) {
                item.other_pic6 = config.appsetting.picHead + item.other_pic6;
            }


        })
        let queryHb = `select name from home_base where id = '${pid}'`;
        let resulthb = yield this._daoModel.query(queryHb);

        r = result.rows
        let hbName = resulthb.rows[0].name;
        return {
            code: 1,
            successed: true,
            rows: r,
            hbName: hbName
        }
    }

    // // 获取公司历史审核
    // * getAllHxByHbId(req, res) {
    //     let r = {};
    //     let hbId = req.params.hbId;
    //     let sql = `SELECT * FROM home_base_hx WHERE pid = ` + hbId + ` order by up`;
    //     let result = yield this._daoModel.query(sql);
    //     r   = result.rows

    //     return {
    //         code: 1,
    //         successed: true,
    //         rows: r
    //     }
    // }


    * getInsertHx(req, res) {
        let r = {};
        let pid = req.body.pid;
        let uid = req.body.uid;
        let a = req.body.a;

        let here = yield this.checkuser(uid, a);
        if (here == 0) {
            return {
                code: -1,
                here: 0,
                successed: true,
                msg: "请重新登陆"
            }
        }

        // 该公司可能有待办的 
        let queryHxByPid = `select * from home_base_hx where pid = '${pid}'`;
        let queryHx = yield this._daoModel.query(queryHxByPid);
        if (queryHx.rows.length != 0) {
            let hxSql = `SELECT * FROM home_base_hx WHERE pid = '${pid}' order by sort desc `
            let queryHx = yield this._daoModel.query(hxSql);
            //如果有待办" 请先完成待办
            if (queryHx.rows[0].ys == 0) {
                r.insertId = queryHx.rows[0].id
                return {
                    code: 1,
                    successed: true,
                    rows: r,
                    msg: "请先完成待办"
                }
            }
        }

        // 先拿到总行数i 并且+1
        let i = queryHx.rows.length + 1
        // let note='第'+i+'次开始检查'
        // let insertHxSql = `INSERT INTO home_base_hx(note, pid, sort) VALUES ('${note}', '${pid}', '${i}')`;
        let today = date.format(new Date(), 'YYYY-MM-DD HH:mm:ss'); //当前时间

        let insertHxSql = `INSERT INTO home_base_hx(create_time, pid, sort, uid) VALUES ('${today}', '${pid}', '${i}', '${uid}')`
        let result = yield this._daoModel.query(insertHxSql);
        r = result.rows

        //修改home_base 的checktime  和hxid 
        let incSql = 'UPDATE home_base SET hxid=' + r.insertId + ',check_time = ' + i + ' WHERE id  = ' + pid;
        yield this._daoModel.query(incSql);


        return {
            code: 1,
            successed: true,
            rows: r
        }
    }

    * getInsertHbAndHx(req, res) {

        let r = {};
        // 插入新公司记录
        let name = req.body.name;
        let fr = req.body.fr;
        let idCard = req.body.id_card;
        let uid = req.body.uid;
        let pics = req.body.pics;
        let phone = req.body.phone;
        let sf = req.body.sf;
        let sq = req.body.sq;
        let qy = req.body.qy;
        let jd = req.body.jd;
        let address = req.body.address;
        let cslx = req.body.cslx;
        let glyphone = req.body.glyphone;
        let glyname = req.body.glyname;
        let a = req.body.a;

        let here = yield this.checkuser(uid, a);
        if (here == 0) {
            return {
                code: -1,
                here: 0,
                successed: true,
                msg: "请重新登陆"
            }
        }

        let resultHB = yield this._daoModel.query(" select *  from home_base where name = '" + name + "' order by id ");
        if (resultHB.rows.length > 0) {

//            let updateHbSql = `update home_base set name='${name}' ,  cslx='${cslx}' , glyname='${glyname}' , fr='${fr}' ,id_card='${idCard}' , uid='${uid}' ,pics='${pics}' , phone='${phone}', glyphone='${glyphone}' ,sf='${sf}' , sq='${sq}' ,qy='${qy}' , jd='${jd}', address='${address}' where id='${resultHB.rows[0].id}'  `
//            yield this._daoModel.query(updateHbSql);
//            return {
//                code: 0,
//                here: 0,
//                successed: true,
//                msg: "公司已保存"
//            }

	         if(resultHB.rows[0].del==0)
	         {
	         	      return {
	                		code: 0,
	                		here: 0,
	                		successed: true,
	                		msg: "该公司已被录入 不能再次新增"
	            		    }
	         	
	         }

        }

        let sql = `INSERT INTO home_base(name, cslx, glyname, fr, id_card, uid, kfs_id, check_time, pics, phone, glyphone, sf, sq, qy, jd, address, xszt) VALUES ('${name}', '${cslx}', '${glyname}', '${fr}', '${idCard}', '${uid}', '${uid}', '0', '${pics}', '${phone}','${glyphone}', '${sf}', '${sq}', '${qy}', '${jd}', '${address}', '0')`;
        let newHb = yield this._daoModel.query(sql);

        // 新公司记录的id
        let hbId = newHb.rows.insertId;
        let hxSql = `SELECT * FROM home_base_hx WHERE pid = '${hbId}' `
        let queryHx = yield this._daoModel.query(hxSql);

        // 先拿到总行数i 并且+1
        let i = queryHx.rows.length + 1
        let today = date.format(new Date(), 'YYYY-MM-DD HH:mm:ss'); //当前时间

        let note = '第' + i + '次开始检查'
        let insertHxSql = `INSERT INTO home_base_hx(create_time, pid, sort, uid) VALUES ('${today}', '${hbId}', '${i}', '${uid}')`;
        let result = yield this._daoModel.query(insertHxSql);
        let hxId = result.rows.insertId;

        let incSql = 'UPDATE home_base SET check_time = ' + i + ', hxid=' + hxId + ' WHERE id  = ' + hbId;
        yield this._daoModel.query(incSql);


        return {
            code: 1,
            successed: true,
            here: here,
            hbId: hbId,
            hxId: hxId
        }
    }

    * getAllPic(req, res) {
        let r = {};
        let pid = req.params.pid || 1;
        let sql = `SELECT  a.name , b.* FROM home_base a inner join  home_base_hx b on a.id=b.pid where b.pid=` + pid + ' order by sort ';
        let result = yield this._daoModel.query(sql);
        result.rows.map((item, index) => {
            if (item.get_live_pic1.indexOf('http') == -1) {
                item.get_live_pic1 = config.appsetting.picHead + item.get_live_pic1;
            }
            if (item.get_live_pic2.indexOf('http') == -1) {
                item.get_live_pic2 = config.appsetting.picHead + item.get_live_pic2;
            }

        })
        r = result.rows
        return {
            code: 1,
            successed: true,
            rows: r
        }
    }


    * getAllPicByhHxid(req, res) {
        let r = {};
        let hxid = req.params.hxid;
        let sql = `SELECT  a.name,a.glyname,a.glyphone,a.sq,a.qy,a.jd,a.address,b.* FROM home_base a inner join  home_base_hx b on a.id=b.pid where b.id=` + hxid + ' order by sort ';
        let result = yield this._daoModel.query(sql);
        // result.rows.map((item, index) => {
        //     if (item.get_live_pic1.indexOf('http') == -1) {
        //         item.get_live_pic1 = config.appsetting.picHead + item.get_live_pic1;
        //     } 
        //     if (item.get_live_pic2.indexOf('http') == -1) {
        //         item.get_live_pic2 = config.appsetting.picHead + item.get_live_pic2;
        //     } 

        // })
        r = result.rows
        return {
            code: 1,
            successed: true,
            rows: r
        }
    }

    * saveShyj(req, res) {
        let r = {};
        let id = req.body.id;
        let sh_note = req.body.sh_note;
        let zg_time = req.body.zg_time;
        let create_time = req.body.date;


        var a1 = Date.parse(new Date(zg_time));  //整改时间
        var a2 = Date.parse(new Date());  //当前时间
        let zgsj = parseInt((a1 - a2))
        if (zgsj < 2) {
            return {
                code: 0,
                successed: false,
                msg: "整改期限需在排查时间之后"
            }
        }




        // 保存审核意见和整改时间
        let sql = `update home_base_hx set sh_note = '${sh_note}', zg_time = '${zg_time}',  create_time = '${create_time}',  del = 0 where id = '${id}'`;
        let result = yield this._daoModel.query(sql);

        // 拿hx的updatetime作为hb更新审核时间 同时修改整改时间 以及颜色和记录违规项目
        let hxsql = `select * from home_base_hx where id= '${id}'`;
        let hxdetail = yield this._daoModel.query(hxsql);
        let hxupdate_time = hxdetail.rows[0].update_time;
        let hxpid = hxdetail.rows[0].pid;
        let hxys = hxdetail.rows[0].ys;
        let hxnote = hxdetail.rows[0].note;
        let hbsql = `update home_base set hxid = 0, sh_time = '${hxupdate_time}', zg_time = '${zg_time}', ys = '${hxys}', note = '${hxnote}' where id = '${hxpid}' `;
        yield this._daoModel.query(hbsql);
        r = result.rows;
        r.sh_note = sh_note;
        r.zg_time = req.body.zg_time;
        return {
            code: 1,
            successed: true,
            rows: r
        }
    }


    * save11(req, res) {
        let r = {};
        let id = req.body.id;
        let sh_note = req.body.sh_note;
        let zg_time = req.body.zg_time;

        var a1 = Date.parse(new Date(zg_time));  //整改时间
        var a2 = Date.parse(new Date());  //当前时间
        let zgsj = parseInt((a1 - a2))
        if (zgsj < 2) {
            return {
                code: 0,
                successed: false,
                msg: "整改期限需在排查时间之后"
            }
        }

        // 保存审核意见和整改时间

        // 设置更新时间
        let today = date.format(new Date(), 'YYYY-MM-DD HH:mm:ss'); //当前时间
        let sql = `update home_base_hx set sh_note = '${sh_note}', zg_time = '${zg_time}', update_time = '${today}', del = 0 where id = '${id}'`;
        let result = yield this._daoModel.query(sql);

        // 拿hx的updatetime作为hb更新审核时间 同时修改整改时间 
        let hxsql = `select update_time, pid from home_base_hx where id= '${id}'`;
        let hxdetail = yield this._daoModel.query(hxsql);
        let hxupdate_time = hxdetail.rows[0].update_time;
        let pid = hxdetail.rows[0].pid;
        let hbsql = `update home_base set sh_time = '${hxupdate_time}', zg_time = '${zg_time}' where id = '${pid}' `;
        yield this._daoModel.query(hbsql);
        r = result.rows;
        r.sh_note = sh_note;
        r.zg_time = req.body.zg_time;
        return {
            code: 1,
            successed: true,
            rows: r
        }
    }

    * checkuser(uid, a) {
        let here = 1;
        let user = yield this._daoModel.query(`SELECT * FROM home_kfs where del=0 and id= ` + uid + ' and a=' + a); //查询没删除的    
        if (user.rows.length == 0) here = 0;
        return here;
    }

    * getSSQByPId(req, res) {
        let here = 1;
        let r = {};
        let parend_id = req.params.pid;
        let districtSql = `SELECT * FROM bas_district WHERE parent_id = '${parend_id}' `
        let queryDistructSql = yield this._daoModel.query(districtSql);

        r = queryDistructSql.rows

        return {
            code: 1,
            successed: true,
            here: here,
            rows: r
        }
    }

}
exports = module.exports = Indexcontroller;
